Chrome下无法用window.close()关闭非脚本打开的页面

今天脚本了里写了一句话:

window.close()

但是浏览器却报了警告提示:Scripts may close only the windows that were opened by it,而且也没有能够关闭我想关闭的页面,怎么办呢?找万能的度娘,搜到的解决方案有:
(1)

window.open('','_self','');
window.close();

(2)

open(location, '_self').close();

这两种我都试过了,还是一样有警告信息,并且无法关闭窗口。
最后一种方案是:

  window.location.href="about:blank";
  window.close();

终于成功关闭窗口啦!

参考:
window.close and self.close do not close the window in Chrome

chrome JS关闭当前页无效问题

--------------update on 29 Jan 2018---------------------
看评论,好多人说还是无法关闭,我已经不记得自己当时的实际应用场景是什么了,我今天自己重新模拟试了一下,具体代码如下:
主页面test.html,两个按钮aaa和 bbb,aaa在自身Tab打开test1.html页面;bbb在新Tab打开test2.html页面

  
  
      
          
        HHH  
        
      
      
        
        
      
    

test1.html页面的代码如下:

  
  
      
          
        HHH  
        
      
      
        

test1

test2.html页面的代码如下:

  
  
      
          
        HHH  
        
      
      
            

test2

测试结果是,test2.html页面可以直接用window.close();就关闭掉;而test1.html页面需要用

 window.location.href="about:blank";
 window.close();

才能关闭(这个关闭其实是以打开一个新的空白页为代价的)。
用其他方式关闭时都无法关闭,且会提示如下警告信息:

 Scripts may close only the windows that were opened by it.

环境:Chrome,版本 64.0.3282.119(正式版本) (32 位)

你可能感兴趣的:(Chrome下无法用window.close()关闭非脚本打开的页面)