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


之前用這段腳本是可以關閉的:

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();

 


免責聲明!

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



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