Home > Web Front-end > JS Tutorial > js code that automatically jumps or closes the current page after waiting for a specified time

js code that automatically jumps or closes the current page after waiting for a specified time

PHP中文网
Release: 2017-03-28 13:58:37
Original
1813 people have browsed it

The code is as follows:

//指定时间之后跳转 
<script language="javascript"> 
function go( ) {//定义函数 
window.location="main.html";//页面跳转 
} 
window.setTimeout("go()",1000);//1秒后执行函数go 
</script> 
//指定时间之后自动关闭 
<script type="text/javascript"> 
function closeMyWindow() { 
window.setTimeout("window.close()", 1000); 
} 
</script> 
<body> 
<p> 
<!--Chrome IE有效,FireFox无效--> 
<input type="button" value="return closeMyWindow()" onclick="return closeMyWindow()" /> 
<br /> 
<!--Chrome IE有效,FireFox无效--> 
<input type="button" value="onclick=&#39;closeMyWindow()&#39;" onclick="closeMyWindow()" /> 
<br /> 
<!--IE有效,FireFox无效--> 
<a href="#" onclick="closeMyWindow()">&#39;closeMyWindow()&#39;</a> 
<br/> 
<!--Chrome IE有效,FireFox无效--> 
<a href="#" onclick="window.close()">&#39;window.close()&#39;</a> 
<br/> 
</p> 
</body>
Copy after login

Related articles:

Click the return button to close the current page and window in WeChat, Alipay and Baidu Wallet

JS summary of several ways to close the current page (window)

Open a new window and close the current page without popping up the closing prompt js code

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