scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面相关的知识,希望对你有一定的参考价值。

不是window.open形式打开的子页面用js的window.close在chrome下就会提示关不了。

网上的很多解决方法都是把当前页面为空,在IE和360浏览器也不能直接关闭页面,翻到stack overflow的解决方案:

 if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1) {  
		 	open(location, ‘_self‘).close();
		 	window.location.href="about:blank";  
	             window.close();  
	    }else {  
	        window.opener = null;  
	        window.open("", "_self");  
	        window.close();  
	        open(location, ‘_self‘).close();
	    }  

open(location, ‘_self‘).close(); 加了这个非火狐和chrome就能直接把当前页面关闭了。

以上是关于scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面的主要内容,如果未能解决你的问题,请参考以下文章

解决 LLVM 错误提示 may only occur zero or one times!

React Relay (react-relay) with Typescript throwing TypeError: Object prototype may only be an Object

May 10th 2017 Week 19th Wednesday

May 15th 2017 Week 20th Monday

May 20th 2017 Week 20th Saturday

May 6th 2017 Week 18th Saturday