Home >Web Front-end >JS Tutorial >Summary of several methods to close windows and pages using JS

Summary of several methods to close windows and pages using JS

怪我咯
怪我咯Original
2017-07-04 15:13:344949browse

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

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