Scripts may close only the windows that were opened by it


關閉當前窗體報以下js錯誤:

Scripts may close only the windows that were opened by it

(腳本只能關閉由它打開的窗口)


 

使用場景,在js中關閉頁面的js,如下:

window.opener = null;
window.open('', '_self');
window.close();

未能通過。

關閉頁面的代碼寫在一個ajax返回的結果中的,如下:

$.ajax({
                type: 'post',
                url: "url",
                success: function (data) {
                    if (data.isOut) {
                        window.opener = null;
                        window.open('', '_self'); window.close();
                    }
                    else {
                        alert(data.msg);
                    }
                },
                error: function (err) {
                    alert("異常:" + err);
                }
            })

解決辦法:

window.location.href="about:blank";
window.close();

成功關閉。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM