Redirect with a Timer


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. var count = 6;
  3. var redirect = "http://www.apphp.com";
  4.  
  5. function countDown(){
  6. var timer = document.getElementById("timer");
  7. if(count > 0){
  8. count--;
  9. timer.innerHTML = "This page will redirect in "+count+" seconds.";
  10. setTimeout("countDown()", 1000);
  11. }else{
  12. window.location.href = redirect;
  13. }
  14. }
  15. </script>
  16.  
  17. Our webpage has beed moved. Please update your bookmarks for the new site.
  18. <br>
  19.  
  20. <span id="timer">
  21. <script type="text/javascript">countDown();</script>
  22. </span>

URL: http://www.apphp.com/index.php?snippet=javascript-redirect-with-timer

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.