开发者

problems with window.open and i.e. security settings

开发者 https://www.devze.com 2023-02-12 13:19 出处:网络
I have a legitimate instance of window.open() on a page on my site. Can I ask the following (1) will i.e. with security set to high block all instances of window.open (I\'ve tested chrome, FF, IE and

I have a legitimate instance of window.open() on a page on my site. Can I ask the following

(1) will i.e. with security set to high block all instances of window.open (I've tested chrome, FF, IE and this appears to be the case)

(2) is there any开发者_StackOverflow社区 way that I can detect this, and so warn the user that their required window will not open.

I'd appreciate any help you can give me on this Paul


try this:

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


Here is a solution (I didn't write this - it's from 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消