从外部iFrame重定向和链接中删除历史记录 [英] Remove history from External iFrame redirects and links

查看:308
本文介绍了从外部iFrame重定向和链接中删除历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个指向外部链接的iframe,一旦iFrame加载,它会执行一些重定向。这会导致在浏览器中添加历史记录,以及用户单击iframe内的链接时。

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.

我想知道是否有办法阻止iframe将历史记录添加到浏览器中?

I was wondering if there was a way to prevent the iframe from ever adding history to the browser?

推荐答案

由于链接是外部的, 最简洁的答案是不。如果您控制iframe的内容,则可以执行一些操作。在将iframe的src属性添加到DOM之后或者如果用户跟随iframe中的链接时,将更新历史记录。通过控制iframe内容,当用户单击链接时,您可以使用postMessage并让父窗口用新的iframe元素替换iframe元素。在同一个域中,您可以使用window.parent。

Since 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.

这篇关于从外部iFrame重定向和链接中删除历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆