Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to prevent an iframe from redirecting parent window, but in such a way that "top level" redirects still work inside the iframe itself?

Tags:

So I've read about the HTML5 sandbox property and I understand that if I want to prevent an iframe redirect its parent window I can use the sandbox property leaving allow-top-navigation out. However when this is done, if the iframe was originally relying on top level redirection, what happens in its place is that it redirects to a blank page, effectively breaking navigation.

Can I prevent the iframe from tinkering its parent window while still allowing "top level" redirects, only letting these work within the context of the iframe instead of being top level?

Edit: For context, I'm working with a third party and its page has a form with a target _top. If the iframe is sandboxed, upon submitting the form users get a blank page, if it's not sandboxed the entire page is redirected. I'm looking for something that would allow to submit the form and show the result within the iframe itself.

like image 980
Mahn Avatar asked Sep 21 '14 10:09

Mahn


People also ask

How do I stop iframe redirects?

You can set sandbox="" , which prevents the iframe from redirecting. That being said it won't redirect the iframe either.

Does iframe support redirect?

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.

How do I prevent an iframe?

The SAMEORIGIN option allows the page to be embedded in an iframe only if the parent page is from the same domain, which presumably is also your code. SAMEORIGIN option can be replaced with DENY , which prevents browsers from loading the page in an iframe regardless of the domain name of the parent page.

What is redirect using iframe?

URL redirect in iframe embedded surveys will be "trapped" inside the iframe. In other words, the new website will only show up inside the iframe window, which is usually not what users desire.


1 Answers

With HTML5 the iframe sandbox attribute was added.

At the time of writing this works on Chrome, Safari, Firefox and recent versions of IE and Opera but does pretty much what you want:

Allows the iframe content to be treated as being from the same origin as the containing document

<iframe src="url" sandbox="allow-same-origin"></iframe>

Browser Compatibility enter image description here


Some Useful links

  • w3schools for sandbox
  • developer.mozilla.org iframe
  • -
like image 121
Suresh Karia Avatar answered Oct 04 '22 21:10

Suresh Karia