Scripts may close only the windows that were opened by it

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

Scripts may close only the windows that were opened by itwindows

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


 

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

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

未能經過。spa

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

$.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);
                }
            })

解決辦法:blog

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

成功關閉。ip

相關文章
相關標籤/搜索