Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks!

like image 898
aviramtsi Avatar asked Mar 22 '13 19:03

aviramtsi


People also ask

How do I stop iframe redirects?

Use sandbox attribute. <iframe src=”Site_URL” sandbox=””> – Full Protection.

Does iframe support redirect?

Some site owners use iFrames to display other Web pages; others add videos or other objects in iFrames and position them around their pages. Using a simple HTML trick, you can use an iFrames to redirect users to other Web pages without changing the URL that appears in their browsers.

Is iframe deprecated?

Overview. The widget is considered deprecated. If you need to use an IFrame, consider the "IFrame Component" widget The Iframe can be used to embed websites in the client.


2 Answers

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/

like image 182
Parris Avatar answered Sep 20 '22 23:09

Parris


Try this:

<iframe align="left" src="http://stackoverflow.com/" sandbox=""></iframe>'
like image 30
Ingo Avatar answered Sep 19 '22 23:09

Ingo