關閉當前窗體報以下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();
成功關閉。