prevent iframe from redirecting parent page

This is the situation: I have on the same domain, an iframe inside my web site. currently, I have no immediate access to the iframe code as of deployment issues.

when the iframe loads, the code inside it detects something that triggers a redirection on the parent page. Temporarily, I want to remove it. I know I can use the onbeforeload, but a warning will be displayed every time the user click on a any link.

Is there a way I can detect the redirection? it happens before the main parent page is fully loaded.

I googled it a lot but still have no working solution.



After reading the spec. I found another solution.

You can set sandbox="", which prevents the iframe frome redirecting. That being said it won't redirect the iframe either. You will lose the click essentially.

Example here: Example without sandbox:

Try this:

<iframe align="left" src="" sandbox=""></iframe>'

Use the onbeforeunload event to ask the user to leave this page or to stay.

    window.onbeforeunload = function(){
        return false; // This will stop the redirecting.

My answer is based on the answers from answers in Stackoverflow!!!

It's a bit of an ugly hack, but here's something that might work (I admit I don't know a whole lot about the workign of iframes). Grab the page you want to put into the iframe via javascript. Use javascript to parse through it until you get to the redirect code, and strip that redirect code out. Then put the result into the iframe. Ugly at best, but it seems like it might work.

Need Your Help

Suitable CMS framework for site projects - advice needed

php sql apache content-management-system query-string

I will be creating a website soon, and as such I have four projects on the go

Why does Tomcat throw 'java.lang.IllegalStateException: Class invariant violation' during undeployment?

java tomcat log4j

I have a web-app (Tomcat 6, log4j 1.2.16), which starts with a listener. Undeploying the application throws the following exception: