Home  >  Article  >  Web Front-end  >  How to automatically close the window with javascript

How to automatically close the window with javascript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-22 10:44:244399browse

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();".

How to automatically close the window with javascript

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(&#39;close.html&#39;, &#39;_self&#39;);    
  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(&#39;&#39;,&#39;_top&#39;);
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn