通过JS实现错误页面中在指定的时间跳到主页

Posted 走在修行的大街上

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过JS实现错误页面中在指定的时间跳到主页相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
    <head>
        <title>
            浏览器对象
        </title>
        <!-- 通过JS实现错误页面中在指定的时间跳到主页 -->
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    </head>
    <body>
        <!--先编写好网页布局-->
        <h3>
            操作成功
        </h3>
        <p>
            <b id="second">
                5
            </b>
            秒后回到主页
            <a href="javascript:goBack();">
                返回
            </a>
        </p>
        <script type="text/javascript">
              //获取显示秒数的元素,通过定时器来更改秒数。
              var sec = document.getElementById("second");
              var i=5;
              var timer = setInterval(function(){
                  i--;
                  sec.innerHTML = i;  
                  if(i ==1){
                      window.location.href="http://baidu.com";
                  }
              },1000)
               
               //通过window的location和history对象来控制网页的跳转。
               function goBack(){
                   window.history.go(-1);
               }
        </script>
    </body>
</html>

以上是关于通过JS实现错误页面中在指定的时间跳到主页的主要内容,如果未能解决你的问题,请参考以下文章