2011-02-22 88 views
1

我在我的网站上的页面上有一个合法的window.open()实例。我能问下window.open问题,即安全设置

(1)将与安全性设置为高挡的window.open所有实例(我测试过铬,FF,IE,这似乎是这种情况)

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

我会很感激的任何帮助,您可以给我这个 保罗

回答

1

试试这个:

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

这对我来说非常好。 – 2012-10-11 16:44:25

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; 
}