Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Chrome redirecting to URL of iframe onload?

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.

like image 338
paul Avatar asked Mar 23 '12 21:03

paul


1 Answers

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.

like image 118
Pavlo Avatar answered Nov 14 '22 04:11

Pavlo