解決新版谷歌瀏覽器無法關閉視窗的問題

魔豆發表於2017-03-30

之前用這段指令碼是可以關閉的:

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

新版的谷歌瀏覽器是無效的,會提示錯誤:Scripts may close only the windows that were opened by it

實在是跟不上瀏覽器更新的節奏~

改成下面的程式碼,可以解決:

var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
    location.href="about:blank";
} else {
    window.opener = null;
    window.open('', '_self');
}
window.close();

 

相關文章