弹出窗口拦截器 IE8 和安全区域
我读过很多关于通过 javascript 代码检测弹出窗口拦截器的帖子,但仍然无法找到我现在遇到的问题的答案。
问题是,当目标 url 是外部网站时,我的浏览器 (IE8) 会阻止访问 window 对象,或者换句话说,尽管允许打开弹出窗口,但 javascript 代码 window.open() 返回 null。相反,对于站点的本地页面,javascript 返回 window 对象。
因此,Internet 选项中的某处似乎有一个安全设置,可以防止抓取打开窗口的处理程序;在这种情况下,有谁知道如何用javascript检测它?
我使用的代码如下,它无法检测到这种情况:
var popup = window.open("http://www.externalsite.com¶m1=value1", "_blank", "");
if (!popup) {
alert('Cannot preview this page because pop-ups are blocked by your browser');
} else {
if (popup != null) { popup.focus(); }
}
I have read many posts regarding detection of popup blocker by javascript code but still have not been able to find an answer to the problem I am having now.
The problem is when the target url is an external website, my browser (IE8) prevents access to window object, or in other words the javascript code window.open() returns null although the popup is allowed to open up. In contrary, for a local page of the site, javascript returns the window object.
Thus it seems there is a security settings somewhere in Internet Options that prevents grabbing the handler of the opened window; in which case, does anyone know how to detect it with javascript?
The code I am using is as follows and it cannot detect this situation:
var popup = window.open("http://www.externalsite.com¶m1=value1", "_blank", "");
if (!popup) {
alert('Cannot preview this page because pop-ups are blocked by your browser');
} else {
if (popup != null) { popup.focus(); }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您打开跨区域和完整性级别的窗口(例如,运行在“中”级别的 Intranet 页面会打开运行在“低”级别的 Internet 页面;或者运行在“低”级别的 Internet 站点将打开运行在“中等”级别的受信任站点),则可能会发生这种情况。这与弹出窗口拦截器无关。
If you open a window that crosses Zones and Integrity levels (e.g. Intranet page running at Medium opens Internet page running at low; or Internet site running at Low opens Trusted site running at medium) this can happen. That has nothing to do with the popup blocker.
当我在 IE8 中测试以下代码时,它可以工作
http:// javascript.internet.com/snippets/popup-blocker-detection-2.html 不是由尼克制作
The following code works when I tested it in IE8
Code found on http://javascript.internet.com/snippets/popup-blocker-detection-2.html not made by Nick