Home > Article > Web Front-end > Summary of several methods to close windows and pages using JS
This article summarizes and introduces several methods of closing windows and pages with JS. Friends who need it can come and refer to it. I hope it will be helpful to everyone.
The first method : JS automatically closes the window at a scheduled time
<script language="javascript"> <!-- function closewin() { self.opener=null; self.close(); } function clock() { i=i-1 document.title="本窗口将在" + i + "秒后自动关闭!"; if(i>0)setTimeout("clock();",1000); else closewin(); } var i=10 clock(); //--> </script>
The second type: JS closes the window without prompt when clicking on the link
<a href="javascript:window.close()" >关闭窗口</a>
The third type: js code that automatically closes the window without prompting
<script language=javascript> <!-- this.window.opener = null; window.close(); //--> </script>
IE6-7 JS method to close the window without prompting
Method one:
js code
function CloseWin() //这个不会提示是否关闭浏览器 { window.opener=null; //window.opener=top; window.open("","_self"); window.close(); }
Method two:
open.html
js code
function open_complex_self() { var obj_window = window.open('close.html', '_self'); obj_window.opener = window; obj_window.focus(); } close.html js 代码 window.close(); 另附: //普通带提示关闭 function closeie(){ window.close(); } //关闭IE6不提示 function closeie6(){ window.opener=null; window.close(); } //关闭IE7不提示 function closeie7(){ window.open('','_top'); window.top.close(); }
The above is the detailed content of Summary of several methods to close windows and pages using JS. For more information, please follow other related articles on the PHP Chinese website!