2011-02-22 31 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; 
}