HTML 定时页面跳转

有 2 种方法可以实现 html 的定时页面跳转,1、meta refresh 实现。2、JavaScript 实现。

1、通过 meta refresh 实现 3 秒后自动跳转到 http://www.cnblogs.com/wuxibolgs329/ 页面。

<!doctype html>
    <html>
      <head>
      <meta charset="utf-8">
      <title>前端笔记</title>
      <meta http-equiv="refresh" content="3;url=http://www.cnblogs.com/wuxibolgs329/">
    </head>
  <body>
  </body>
</html>

2、通过 JavaScript 实现 8 秒后自动跳转到 http://www.cnblogs.com/wuxibolgs329/  页面。

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>    
    </head>
    <body>
        <span id="s"></span>
        <script type="text/javascript">
            var s = document.getElementById('s');        
            var time = 8; //时间,秒                    
            function Redirect() {        
                window.location = "http://www.baidu.com/";        
            }        
            var i = 0;        
            function dis() {        
                s.innerHTML = "还剩" + (time - i) + "";        
                i++;        
            }        
            timer = setInterval('dis()', 1000); //显示时间                    
            timer = setTimeout('Redirect()', time * 1000); //跳转
        </script>
    </body>
</html>

 

posted @ 2016-12-21 22:56  以茜为贵  阅读(3431)  评论(5编辑  收藏  举报