window.open和安全设置的问题

时间:2011-02-22 22:00:57

标签: javascript

我的网站页面上有一个合法的window.open()实例。我可以问以下

(1)将ie安全设置为高阻止window.open的所有实例(我已经测试了chrome,FF,IE,这似乎就是这种情况)

(2)有什么方法可以检测到这一点,因此警告用户他们所需的窗口不会打开。

我很感激你能给我的任何帮助 保罗

2 个答案:

答案 0 :(得分:1)

试试这个:

var x = window.open(url);
if (!x){
alert('your window is blocked!');
}

答案 1 :(得分:0)

这是一个解决方案(我没有写这个 - 它来自here):

function _hasPopupBlocker(poppedWindow) {
    var result = false;

    try {
        if (typeof poppedWindow == 'undefined') {
            // Safari with popup blocker... leaves the popup window handle undefined
            result = true;
        }
        else if (poppedWindow && poppedWindow.closed) {
            // This happens if the user opens and closes the client window...
            // Confusing because the handle is still available, but it's in a "closed" state.
            // We're not saying that the window is not being blocked, we're just saying
            // that the window has been closed before the test could be run.
            result = false;
        }
        else if (poppedWindow && poppedWindow.test) {
            // This is the actual test. The client window should be fine.
            result = false;
        }
        else {
            // Else we'll assume the window is not OK
            result = true;
        }

    } catch (err) {
        //if (console) {
        //    console.warn("Could not access popup window", err);
        //}
    }

    return result;
}