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.
You can set sandbox="" , which prevents the iframe from redirecting. That being said it won't redirect the iframe either.
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.
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.
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.
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:
<iframe src="url" sandbox="allow-same-origin"></iframe>
Browser Compatibility
Some Useful links
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With