JS關閉當前窗口


 1  function closePage() {
 2         if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1) {
 3             window.location.href = "about:blank";
 4             window.close();
 5         } else {
 6             window.opener = null;
 7             window.open("", "_self");
 8             window.close();
 9         }
10     }
11 
12 
13     $('#login-out').on('click', function () {
14         $.ajax({
15             type: 'post',
16             url: '/Account/Logout',
17             data: { login_from: 'agent' },
18             success: (res) => {
19                 // console.log("退出成功");
20                 // window.location.href = "/Account/Login";
21                 var hideThirdAgentId = $('#hide-ThirdAgentId').val();
22                 if (hideThirdAgentId) {
23                     window.location.href = "/Account/Login";
24                 } else {
25                     //window.opener = null;
26                     //window.open('', '_self');
27                     //window.close();
28                     closePage();
29                 }
30 
31             }
32         });
33 
34     });

 

 

谷歌瀏覽器和火狐瀏覽器存在兼容,不能使用下面三行代碼進行常規瀏覽器關閉,會提示

Scripts may close only the windows that were opened by it  (腳本只能關閉它所打開的窗口)

其他瀏覽器可以正常關閉

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

 


免責聲明!

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



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