user1941752
user1941752

Reputation: 37

Preventing iframe top-level redirect

I'm trying to prevent a top-level redirect from an iframe. My code works great, but any time a user tries to leave the page, they get asked if they want to stop the script and navigate, or not. This is for a kind of high end website, so I was wondering if there was a way around this dialog box? Here is my current code:

window.onbeforeunload = function(){
    return false;
}

I'm using sandbox="" in my iframe to prevent the dialog box from poping up onload. If anyone knows how to prevent this from happening upon leaving the page and is willing to give me some advice, it'd be greatly appreciated!

Upvotes: 0

Views: 1376

Answers (1)

suff trek
suff trek

Reputation: 39767

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.

Upvotes: 1

Related Questions