It is possible for a iframe to redirect the page it is on?
Example:
You go to www.fuu.com
On fuu.com there is a iframe
In that iframe is a website the redirects to another website.
Is it possible for fuu.com to be redirected? instead on just the iframe going to another page?
No. An iframe is treated as a separate document with its own DOM. A redirect within the iframe is treated as a redirect only within that iframe.
In other words, The main page can not be redirected by an iframe.
EDIT: I was wrong. Consider the following situation
Top Page
<html>
<body>
<iframe src="redirect.html"></iframe>
</body>
</html>
redirect.html
<html>
<head>
<script>
window.top.location = "http://www.w3schools.com";
</script>
</head>
</html>
That does redirect the top page to w3schools.com
To prevent this type of thing, you can remove that by using the following
<html>
<body>
<iframe src="redirect.html" sandbox="allow-scripts"></iframe>
</body>
</html>
In chrome, this would give you the following error:
Unsafe JavaScript attempt to initiate navigation for frame with URL 'http://127.0.0.1/scg/?search=&submit=Search' from frame with URL 'http://127.0.0.1/scg/iframeRedirect.html'. The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set.
The allow-scripts allows Javascript to still be executed in the iframe but removes window.top from allowing to execute. Check this out
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