如何阻止来自 iframe 的弹出窗口?
我正在嵌入具有退出弹出窗口的页面。当您关闭页面时,它会自动启动一个弹出窗口。
如何禁用退出时来自 iframe 的弹出窗口?
I'm embedding page that has an exit pop-up. When you close the page, it automatically launches a pop-up window.
How to disable pop-ups coming from the iframe on exit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是一个很老的问题,但我想我会提供一个更新的解决方案,因为这是谷歌的最佳结果。
如果您想阻止 iframe 打开窗口,您可以在 iframe 上使用新的 HTML5“沙箱”属性。
https://developer.mozilla.org/en/docs/Web/HTML /Element/iframe
这应该可以防止它执行任何操作(除了运行 javascript,这可能是页面正常运行所必需的):
Quite an old ask, but I thought I'd offer a newer solution since this is the top result in google.
If you want to block an iframe from opening windows, you can use the new HTML5 "sandbox" attribute on your iframe.
https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe
This should keep it from doing anything (except running javascript which may be required for the page to function correctly):
如果您想阻止 POP 广告或来自您在 IFRAME 中显示的网站的内容 - 这相当简单。
创建您的 iframe 指向的 framefilter.php 和 javascriptfilter.php 。
您可以修改它以满足您的需求,例如 onload blah blah 等。
但按现状 - 它对我来说已经工作得很好很长一段时间了。希望有帮助。
将标准 IFRAME HTML 替换为:
Framefilter.php
javascriptfilter.php
If you are wanting to block something like POP up ads or something coming from a website you are showing in an IFRAME - it's fairly easy.
Make a framefilter.php and javascriptfilter.php which your iframe points to.
You can modify it to meet your needs such as the onload blah blah and etc.
But as/is - it's been working fine for me for quite a while. Hope it helps.
Replace your standard IFRAME HTML with this:
Framefilter.php
javascriptfilter.php
在 IFrame 元素上设置沙箱属性应该可以。
Setting the sandbox attribute on the IFrame element should work.
我认为这是不可能的。
我看到的唯一可能性本质上是非技术性的:与 iframe 内运行该网站的任何人联系,检查他们是否可以为您制作一个特殊的页面,一个没有这样的 onunload 弹出窗口的页面。在大多数情况下,要么
I don't think this is possible.
The only possibility I see is non-technical in nature: check with whoever runs that site inside the iframe if they could make a special page for you, one without such onunload popup. In most cases, either
事实上,这是可能的。至少在很多情况下是这样。通常,iframe 中的代码将运行类似
top.window.open(...)
的代码来打开弹出窗口。您可以重新定义 window.open 方法,使其仍然存在,但不会打开窗口。例如:`
window.alias_open = window.open;
window.open = 函数(url, 名称, 规格, 替换) {
// 什么也不做,或者做一些聪明的事情...
}
`
如果您仍希望打开一些弹出窗口,可以将
window.open
正文中的网址列入白名单,并根据需要调用alias_open
。Actually, this is possible. Well at least in many cases. Often, the code in the iframe will be running something like
top.window.open(...)
to open a pop-up. You can redefine the window.open method so it still exists, but doesn't open a window. E.g.:`
window.alias_open = window.open;
window.open = function(url, name, specs, replace) {
// Do nothing, or do something smart...
}
`
If you still want some pop-ups to open, you can whitelist urls within the body of
window.open
, and callalias_open
as needed.我不确定这是否有效,但你可以尝试双 Iframing。在免费博客帐户中 iframe 该网站,然后使用延迟加载代码 iframe 该博客帐户。因此弹出窗口将在页面加载之前发生,让我知道它是否有效。
I'm not sure if this would work but you could try double Iframing. Iframe the site in a free blogger account, then iframe the blogger account with a delay loading code. so the popup will occur before the page is loaded let me know if it works.
使用现代浏览器 - 它们都具有不错的弹出窗口阻止功能
Use a modern browser - they all come with decent pop-up blocking capabilities