I have a div with an iframe in it, and the iframe loads a page from another site (cross-domain). When the page loads in firefox it works fine and shows the page with the iframe in the div. However in Chrome, it automatically redirects to the iframe URL when the page loads. Any idea why this is happening and if it's possible to do what I'm trying to do in Chrome?
Notes: I'm not trying to do any cross-domain communication, just want to let users access the other site from within a page on my site. This also happens in Safari, so maybe it's a webkit thing.
Sandboxed iframe may be solution to your problem. It's supported by both Safari and Chrome, and will not effect Firefox1. You can use it like so:
<iframe sandbox="allow-forms allow-same-origin allow-scripts" src="http://stackoverflow.com"></iframe>
By not adding allow-top-navigation
there you are preventing an iframe to redirect the whole page.
You can read more about it on W3C.org.
1 Starting from version 17, Firefox also supports sandboxed iframe.
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