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

 

posted @ 2020-03-28 11:48  w1433189426  阅读(4156)  评论(0编辑  收藏  举报