Using JavaScript Countdown to Redirect to a Specific Webpage
javascript countdownauto redirect pagehtml countdown timerwebsite maintenance pagejavascript redirect code
Published·Modified·
Some users may have top-level domains they do not intend to use immediately and wish to redirect visitors to another website. Using JavaScript for a countdown not only notifies users but also achieves the redirection goal. Below is a simple JavaScript snippet for reference.
Copy the code below and save it as xxx.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="小z">
<meta name="Keywords" content="男女派">
<meta name="Description" content="男女派">
<title>男女派官网</title>
<style type = "text/css">
body {
font-family:微软雅黑;
font-size:14px;
}
.show {
width:600px;
height:auto;
margin-left:auto;
margin-right:auto;
margin-top:12%;
text-align:center;
/*background-color:#fffcef;*/
/*border:1px solid #ff7102;*/
color:#33cc33;
padding:10px;
line-height:20px;
}
.show a {
text-decoration:none;
color:#0066cc;
}
</style>
</head>
<body onload = "jump()">
<div class = "show">
<center><img src = "https://blog.xiaoz.org/wp-content/uploads/2014/11/loading.gif" width = "120" height = "120" /></center>
网站正在建设中...敬请期待。<span id = "hm">5</span>秒后将跳转到男女派博客!<br />
如果5秒后无反应,请<a href = "http://blog.nannvpai.com" title = "访问男女派博客">点此链接</a>。
</div>
<script>
function url() {
document.location= "http://blog.nannvpai.com";
}
function foure() {
document.getElementById("hm").innerHTML = 4;
setTimeout("three()",1000);
}
function three() {
document.getElementById("hm").innerHTML = 3;
setTimeout("two()",1000);
}
function two() {
document.getElementById("hm").innerHTML = 2;
setTimeout("one()",1000);
}
function one() {
document.getElementById("hm").innerHTML = 1;
setTimeout("zero()",1000);
}
function zero() {
document.getElementById("hm").innerHTML = 0;
return url();
}
function jump() {
var t = setTimeout("foure()",1000);
}
</script>
</body>
</html>
Demo Address: www.nannvpai.com (JavaScript Demo)