首页 > Web开发 > 详细

JS关闭当前窗口

时间:2020-03-28 12:28:22      阅读:232      评论:0      收藏:0      [点我收藏+]
 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();

 

JS关闭当前窗口

原文:https://www.cnblogs.com/WQ1992/p/12586539.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!