Javascript, Track Iframes Redirecting Top Window

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



Leave a reply



Submit