admin管理员组文章数量:1356930
I have an iframe pointing to an external link that does some redirections as soon as the iFrame loads. This causes added history into the browser and also when users click on links inside the iframe.
This causes a weird user experience because you have extra back history states pointing to the same parent page.
I was wondering if there was a way to prevent the iframe from ever adding history to the browser?
I have an iframe pointing to an external link that does some redirections as soon as the iFrame loads. This causes added history into the browser and also when users click on links inside the iframe.
This causes a weird user experience because you have extra back history states pointing to the same parent page.
I was wondering if there was a way to prevent the iframe from ever adding history to the browser?
Share Improve this question asked Jan 25, 2015 at 14:26 Andrew CetinicAndrew Cetinic 2,83530 silver badges48 bronze badges 05 Answers
Reset to default 3 +50Since the link is external, the short answer is no. If you are in control of the content of the iframe there are a few things you can do. History will be updated any time the src attribute of an iframe is changed after it has been added to the DOM or if the user follows a link in the iframe. With control of the iframe content, when a user clicked a link, you could use postMessage and have the parent window replace the iframe element with a new one. In the same domain, you could just use window.parent.
You can try to use sandbox="" attribute to prevent the iframe from redirecting.
<iframe src="http://example./" sandbox=""></iframe>
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.
Source (MDN)
location.replace() | MDN
http://jsbin./coregedoze/2 Here is a link of my code with an iframe, this has no sandbox attribute- as this attribute only works with HTML5 and limited browser version. I rechecked this code and it wont save any history. Only case is if you change your source of the iframe the whole page reloads and makes another entry into history, which can be avoided using sandbox="value" as mentioned in above answer by JAYDEN LAWSON. Another way around is declare your links in your page out of iframe and call them in iframe like traget="iframe_a" , where iframe_a is your iframe name. hope this helps :-)
No, You can do almost nothing with an iframe which has src set to another domain because of XXS
本文标签: javascriptRemove history from External iFrame redirects and linksStack Overflow
版权声明:本文标题:javascript - Remove history from External iFrame redirects and links - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743951117a2567305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论