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

How to close javascript window

coldplay.xixi
coldplay.xixiOriginal
2021-03-31 17:54:474213browse

Methods for closing JavaScript windows: 1. JS automatically closes the window at a scheduled time; 2. Clicking on the link does not prompt JS to close the window; 3. The window does not prompt the JS code to automatically close.

How to close javascript window

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to close the javascript window:

The first one: 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 code that 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 prompt

<script language=javascript> 
<!-- 
this.window.opener = null; 
window.close(); 
//--> 
</script>

Related free learning recommendations: javascript video tutorial

The above is the detailed content of How to close javascript window. 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