1. 程式人生 > >scripts may close only the windows that were opened by it 瀏覽器JS控制無法關閉當前頁面

scripts may close only the windows that were opened by it 瀏覽器JS控制無法關閉當前頁面

解決方案 360瀏覽器 當前 火狐 就會 navigator opener ati hat

不是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控制無法關閉當前頁面