簡體   English   中英

window.open和安全設置的問題

[英]problems with window.open and i.e. security settings

我的網站頁面上有window.open()的合法實例。 我可以問以下問題嗎

(1)將安全性設置為高,從而阻止window.open的所有實例(我已經測試了chrome,FF,IE,並且似乎是這種情況)

(2)有什么方法可以檢測到這一點,因此警告用戶其所需的窗口將不會打開。

謝謝您能給我這個保羅的任何幫助

嘗試這個:

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

這是一個解決方案(我沒有寫這個-這是從這里開始的 ):

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM