Javascript countdown N seconds after the page automatically jump code

  • 2020-03-30 04:35:37
  • OfStack


<title>JS Countdown page automatically jump code </title>  
<script language="JavaScript" type="text/javascript">
    function delayURL(url) {
        var delay = document.getElementById("time").innerHTML;
        if(delay > 0) {
            delay--;
            document.getElementById("time").innerHTML = delay;
        } else {
            window.top.location.href = url;
        }
       t = setTimeout("delayURL('" + url + "')", 1000);
    } function stop1(){  
t && clearTimeout(t);
}
</script>
<span id="time" style="background: #00BFFF">1000</span> Automatic jump after seconds, if not jump, please click the link below <a href="http://www.baidu.com"> My baidu </a>
<input type="button" value=" Stop jumping " onclick="stop1();">
<script type="text/javascript">
delayURL("http://www.baidu.com");
</script>

The code is very simple, but very practical, friends according to their own needs in their own projects.


Related articles: