收集一些常用的代码
 

window.close

今天写页面时,发现chrome上使用window.close方法有时不能关闭页面。

搜索google时从这里 发现下面一段文字:


When this method (window.close)  is called, the referenced window is closed.

This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

意思是 window.close 关闭的是 window.open 方法打开的页面(默认关闭当前页面)。


所以最好用下面函数关闭窗口:

function closeWin(){

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

}


***********************************************

StackOverFlow上看到一个人才给出的方法:


In the body tag:

<body onload="window.open('','_self','');">

To close the window:

<a href="javascript: window.close();">



 

 
评论
© 代码|Powered by LOFTER