如果尝试重定向用户,则在新选项卡中打开 iframe 源

发布于 2024-09-28 00:26:24 字数 214 浏览 0 评论 0原文

众所周知,许多网站使用 JavaScript 代码来阻止使用 iframe 浏览它们。我希望我的 iframe 的行为如下:如果网站没有这样的代码并且不尝试重定向用户,则其内容应显示在 iframe 中。但如果它尝试重定向,则应在新选项卡中打开它(就像带有 target="_blank" 的链接一样)。是否可以使用 onUnload 或任何其他技术来完成这样的事情?

预先感谢,
迈克尔.

It's a known fact that a lot of websites use javascript codes to prevent from browsing them using iframes. I would like then my iframe to behave like this: if the site doesn't have such a code and isn't trying to redirect the user, its content should be shown in the iframe. But if it's trying to redirect, it should be opened in a new tab (just like links with target="_blank"). Is it possible to use onUnload or any other techniques to do such a thing?

Thanks in advance,

Michael.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

站稳脚跟 2024-10-05 00:26:24

如果可能的话,实现这一目标将极其困难、复杂和笨拙。在导航到链接之前需要预测目标站点的行为。 再想一想,这实际上可以使用 onbeforeunload 事件来实现,但我预计弹出窗口拦截器等会带来很多麻烦。

我假设您有外部链接,并且希望显示一些“返回原始站点”栏,以免失去访问者。

我要做的一个简单的解决方法是在这两种情况下在新的 target="_blank" 窗口中打开网站,并让“返回网站”链接使用 window.关闭()。

This will be extremely tough and complex and kludgy to achieve, if it's possible at all. It would require to predict the target site's behaviour before navigating to the link. On second thought, this may in fact be possible using the onbeforeunload event but I expect a lot of trouble with pop-up blockers and the like.

I am assuming you have external links, and would like to show some "return to original site" bar in order to not lose visitors.

What I would do as a simple workaround is open the site in a new target="_blank" window in both cases, and have your "return to site" link close the window using window.close().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文