Home > Article > Web Front-end > How to automatically close the window with javascript
Method: 1. Use the setTimeout() method to close, with the syntax "setTimeout("clock();",1000);"; 2. The window will automatically close without prompts, with the syntax "this.window.opener=null ; window.close();".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The first type: 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:The window does not prompt the js code for automatic closing
<script language=javascript> <!-- this.window.opener = null; window.close(); //--> </script>
Extended information:
IE6-7 JS method to close the window without prompting
Method 1:
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 code
window.close();
Attached:
//普通带提示关闭 function closeie(){ window.close(); } //关闭IE6不提示 function closeie6(){ window.opener=null; window.close(); } //关闭IE7不提示 function closeie7(){ window.open('','_top'); window.top.close(); }
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to automatically close the window with javascript. For more information, please follow other related articles on the PHP Chinese website!