How to prevent IFRAME from redirecting top-level window
Try using the onbeforeunload property, which will let the user choose whether he wants to navigate away from the page.
Example: https://developer.mozilla.org/en-US/docs/Web/API/Window.onbeforeunload
In HTML5 you can use sandbox property. Please see Pankrat's answer below.
http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/
Stop an embedded iframe from redirecting
As your iframe is obviously served by another domain, standard solutions cannot be used. You can't read or modify the iframe nor its document.
But you can put an invisible div over it like this : http://jsfiddle.net/dystroy/Afg3K/
<div id=a></div>
#a{
position:fixed;
top:0;
left:0;
width:224px;
height:429px;
}
But most of the times, those things are forbidden by the iframe inclusion contract. Look at your agreement before you do it.
Preventing iframe top-level redirect
Actually since you already using sandbox=""
in your IFRAME, it already prevents it from changing top-level location. You can safely remove your onbeforeunload
event handler.
Note: sandbox=""
does not work in IE9 and below.
Related Topics
Why Are Duplicate Id Values Not Allowed in Html
Does Html5 Allow Drag-Drop Upload of Folders or a Folder Tree
How to Get the Information from a Meta Tag With JavaScript
Calling Webpacked Code from Outside (Html Script Tag)
Method to Show Native Datepicker in Chrome
What Is Offsetheight, Clientheight, Scrollheight
How to Make a Link Open Multiple Pages When Clicked
Jquery: Simulating a Click on a ≪Input Type="File" /≫ Doesn't Work in Firefox
Html5 Canvas Todataurl Returns Blank
Difference Between Node Object and Element Object
Which Browsers Support ≪Script Async="Async" /≫
Angularjs - Value Attribute on an Input Text Box Is Ignored When There Is a Ng-Model Used
Set Custom Html5 Required Field Validation Message
How to Check Whether a Checkbox Is Checked in Jquery
How to Make Ng-Bind-Html Compile Angularjs Code