js 3秒後跳轉頁面的實現代碼

來源:互聯網
上載者:User

隔多少秒後自動跳轉到其它頁(js指令碼)

方法一:

在<head></head>之間加入js

複製代碼 代碼如下:
<script language="javascript">
var secs = 3; //倒計時的秒數
var URL ;
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; }
}
</script>

然後在<body>裡面加上<body onload="Load('index.asp')">   index.asp為自己要跳轉的頁面。

在<body></body>之間加上<div id="ShowDiv"></div>

方法二:

複製代碼 代碼如下:
<p style="text-indent: 2em; margin-top: 30px;">
系統將在 <span id="time">5</span> 秒鐘後自動跳轉至新網址,如果未能跳轉,<a href="http://www.jb51.net" 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.jb51.net";
        }       
    }
</script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.