[javascript]各种页面定时跳转(倒计时跳转)代码总结

(1)使用setTimeout函数实现定时跳转(如下代码要写在body区域内)

1 <script type="text/javascript">
2 //3秒钟之后跳转到指定的页面
3 setTimeout(window.location.href='http://www.baidu.com',3);
4 </script> 

(2)html代码实现,在页面的head区域块内加上如下代码

1 <!--5秒钟后跳转到指定的页面-->
2 <meta http-equiv="refresh" content="5;url=http://www.baidu.com" /> 

(3)稍微复杂点,多见于登陆之后的定时跳转

 1 <!doctype html>
 2 <head>
 3 <meta charset=utf-8" />
 4 <title>js定时跳转页面的方法</title>
 5 </head>
 6 <body>
 7 <script>
 8 var t=10;//设定跳转的时间
 9 setInterval("refer()",1000); //启动1秒定时
10 function refer(){
11 if(t==0){
12 location="http://www.baidu.com"; //#设定跳转的链接地址
13 }
14 document.getElementById('show').innerHTML=""+t+"秒后跳转到百度"; // 显示倒计时
15 t--; // 计数器递减
16 //本文转自:
17 }
18 </script>
19 <span id="show"></span>
20 </body>
21 </html> 
原文地址:https://www.cnblogs.com/lipcblog/p/6724643.html