Is it possible for the iframe to redirect to the parent page?
1 answer
Not. IFrame is treated as a separate document with its own DOM. A redirect within an iframe is treated as a redirect only within that iframe.
In other words, the master page cannot be redirected using 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>
This redirects the top page to w3schools.com
To prevent this type of thing, you can remove it using the following
<html>
<body>
<iframe src="redirect.html" sandbox="allow-scripts"></iframe>
</body>
</html>
In chrome, this will result in 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.
Permission scripts allow Javascript to still execute in the iframe, but removes window.top from execution permission. check it
+3
source to share