prevent iframe from redirecting parent page

20,401

Solution 1

After reading the w3.org 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: http://jsfiddle.net/ppkzS/1/
Example without sandbox: http://jsfiddle.net/ppkzS/

Solution 2

Try this:

<iframe align="left" src="http://stackoverflow.com/" sandbox=""></iframe>'
Share:
20,401
aviramtsi
Author by

aviramtsi

Updated on March 10, 2020

Comments

  • aviramtsi
    aviramtsi about 4 years

    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.

    Thanks!

  • Ben Barden
    Ben Barden about 11 years
    Specifically called out in the original post as something that the OP did not want