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/
Redirect parent window from an iframe action
window.top.location.href = "http://www.example.com";
Will redirect the top most parent Iframe.
window.parent.location.href = "http://www.example.com";
Will redirect the parent iframe.
Redirect parent iFrame from nested iFrame
If you have access to the parent iframe's domain, you can simply redirect it using:
window.parent.location = 'http://new.location.com';
Small parent
/top
example
<Browser>
<iframe1>
<iframe2>
</iframe2>
</iframe1>
</Browser>
Inside iframe2 the following are true:
window.parent.parent == window.top // true
window.parent == window.top.frames[0] // true
Note: the following example presumes browser
and iframe
1
& 2
all are from the same domain
any way of redirecting the whole page from script inside iframe
You cannot use the window.top.location if your frame and the top level page are on different domains.
A similar answer.
Posting to iframe, but the iframe redirects the top window to action url instead of self?
I think that what can happend here is that THE_URL is some protected page that break frames. Perhaps wikipedia or other. With a code like this one:
if (top.location != location) {
top.location.href = document.location.href ;
}
Related Topics
How to Compare Two Arrays Using Lodash (The Order Matters)
Jquery Change Event Called Two Times
Reactjs How to Call a Component Function from Another Function on the Same File
How to Customize Header Cell in Pdf Using Jspdf-Autotable Plugin
How to Pass Value to a Onclick Function in (Jade)Pug
Matching a Forward Slash With a Regex
How to Include a JavaScript in a Jsp Page
Prevent Bootstrap Modal Window from Closing on Form Submission
How to Remove All Li Element of Same Class Except First Li Element in Jquery or JavaScript
How to Use Lodash to Remove Keys from a Json Object
How to Change the State Correctly (Read-Only Error)
Starting the Week on Monday With Isoweekday()
Disabled Button Onclick Event Fires
How to Refresh an Angular Component
Basic Open Source JavaScript Image Editor
Easiest Way to Mask Characters in Html(5) Text Input