Saturday 22 September 2018

How to Redirect with a Timer Using Javascript

You can use JavaScript window.location to redirect a visitor to a required page. You may have seen this feature used by sites with full page ads, or to redirect visitors to the site's new domain name. You can add also a timer to the script that will allow the page to redirect and the visitors will not need to click a link or type in the new URL.


<script type="text/javascript">
var count = 6;
var redirect = "https://www.apphp.com";
 
function countDown(){
    var timer = document.getElementById("timer");
    if(count > 0){
        count--;
        timer.innerHTML = "This page will redirect in "+count+" seconds.";
        setTimeout("countDown()", 1000);
    }else{
        window.location.href = redirect;
    }
}
</script>
 
Our webpage has beed moved. Please update your bookmarks for the new site.
<br>
 
<span id="timer">
<script type="text/javascript">countDown();</script>
</span>

Please like or share with friends and don’t forget say hello if you find it interesting, more are still coming to codexpress labs Devs users.
Previous Post
Next Post

post written by:

0 Comments:

Hit me with a comment!