ygunoil
当页面首次打开时,浏览器认为是不安全的并不能直接关闭当前窗口。这不是bug,有解释的链接:
https://stackoverflow.com/questions/25937212/window-close-doesnt-work-scripts-may-close-only-the-windows-that-were-opene
https://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome
只有当页面从别的页面打开时或者window.open()打开时,window.close()才起作用或则执行两次可关闭页面
不同的浏览器有不用的兼容问题
代码如下:
if (navigator.userAgent.indexOf(\'MSIE\') > 0) { // close IE
   if (navigator.userAgent.indexOf(\'MSIE 6.0\') > 0) {
      window.opener = null;
      window.close();
   } else {
      window.open(\'\', \'_top\');
      window.top.close();
   }
} else { // close chrome;It is effective when it is only one.
   window.opener = null;
   window.open(\'\', \'_self\');
   window.close();
}

  

分类:

技术点:

相关文章:

  • 2021-10-19
  • 2021-12-23
  • 2021-12-31
  • 2021-10-10
  • 2021-12-05
  • 2021-11-13
  • 2021-07-19
猜你喜欢
  • 2021-09-10
  • 2021-11-28
  • 2021-12-23
  • 2021-12-03
  • 2021-12-23
  • 2021-12-23
  • 2021-09-18
相关资源
相似解决方案