Js 3 seconds after the jump page implementation code

  • 2020-03-30 02:21:35
  • OfStack

Automatically jump to another page after how many seconds (js script)

Method one:

In < Head> < / head> Between adding js


<script language="javascript">
var secs = 3; //Seconds count down
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 = ' Will be in '+num+' Automatically redirects to home page after 2 seconds ' ;
if(num == 0) { window.location = URL; }
}
</script>

Then in < Body> Plus < The body onload = "Load (' index. The asp ')" >     Index. Asp for their own to jump to the page.

In < Body> < / body> Plus < Div id = "ShowDiv" > < / div>

Method 2:


<p style="text-indent: 2em; margin-top: 30px;">
 System will be in  <span id="time">5</span>  It will automatically jump to the new url after seconds. If it fails to jump, <a href="//www.jb51.net" title=" click to access "> Please click </ 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 = "//www.jb51.net";
        }        
    } 
</script>


Related articles: