弹出窗口拦截器 IE8 和安全区域

发布于 2024-10-16 11:33:36 字数 594 浏览 2 评论 0原文

我读过很多关于通过 javascript 代码检测弹出窗口拦截器的帖子,但仍然无法找到我现在遇到的问题的答案。

问题是,当目标 url 是外部网站时,我的浏览器 (IE8) 会阻止访问 window 对象,或者换句话说,尽管允许打开弹出窗口,但 javascript 代码 window.open() 返回 null。相反,对于站点的本地页面,javascript 返回 window 对象。

因此,Internet 选项中的某处似乎有一个安全设置,可以防止抓取打开窗口的处理程序;在这种情况下,有谁知道如何用javascript检测它?

我使用的代码如下,它无法检测到这种情况:

var popup = window.open("http://www.externalsite.com&param1=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 技术交流群。

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

发布评论

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

评论(2

顾北清歌寒 2024-10-23 11:33:36

如果您打开跨区域和完整性级别的窗口(例如,运行在“中”级别的 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.

紫竹語嫣☆ 2024-10-23 11:33:36

当我在 IE8 中测试以下代码时,它可以工作

function detectPopupBlocker() {
        var test = window.open(null,"","width=100,height=100");
        try {
                test.close();
                alert("Pop-ups not blocked.");
        } catch (e) {
                alert("Pop-ups blocked.");
        }
}

// Created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(detectPopupBlocker);

http:// javascript.internet.com/snippets/popup-blocker-detection-2.html 不是由尼克制作

The following code works when I tested it in IE8

function detectPopupBlocker() {
        var test = window.open(null,"","width=100,height=100");
        try {
                test.close();
                alert("Pop-ups not blocked.");
        } catch (e) {
                alert("Pop-ups blocked.");
        }
}

// Created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(detectPopupBlocker);

Code found on http://javascript.internet.com/snippets/popup-blocker-detection-2.html not made by Nick

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