Posted By

apphp-snippets on 02/27/13


Tagged

js redirect timer


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

_duddy
Abiotic
Priestd09
lionminister
Beppoi
Kreazin
jakkrith


Redirect with a Timer


 / Published in: JavaScript
 

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

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.

  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>

Report this snippet  

You need to login to post a comment.