js 3秒后跳转页面的实现代码

隔多少秒后自动跳转到其它页(js脚本)

方法一:

 $(function(){
       Load(URL);
    })
    var secs = 3; //倒计时的秒数
    var URL = "<?= url('/infomation/businessapply')?>" ;
    function Load(url){
        URL = url;
        for(var i=secs;i>=0;i--)
        {
            window.setTimeout('doUpdate(' + i + ')', (secs-i) * 1000);
        }
    }
    function doUpdate(num)
    {
        document.getElementById('ShowDiv').innerHTML = '将在'+num+'秒后自动跳转到主页' ;
        if(num == 0) { window.location = URL; }
    }

方法二:

<p style="text-indent: 2em; margin-top: 30px;">
系统将在 <span id="time">5</span> 秒钟后自动跳转至新网址,如果未能跳转,<a href="http://www.baidu.com" title="点击访问">请点击</a>。</p>
<script type="text/javascript">  
    delayURL();    
    function delayURL() { 
        var delay = document.getElementById("time").innerHTML;
 var t = setTimeout("delayURL()", 1000);
        if (delay > 0) {
            delay--;
            document.getElementById("time").innerHTML = delay;
        } else {
     clearTimeout(t); 
            window.location.href = "http://www.baidu.com";
        }        
    } 
</script>
原文地址:https://www.cnblogs.com/wicub/p/4849498.html