Home > Web Front-end > JS Tutorial > How to close javascript window

How to close javascript window

coldplay.xixi
Release: 2023-01-04 09:33:37
Original
4242 people have browsed it

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>
Copy after login

The second type: JS code that closes the window without prompt when clicking on the link

<a href="javascript:window.close()" >关闭窗口</a>
Copy after login

The third type: JS code that automatically closes the window without prompt

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template