I want to do a redirect count so that the user can see the count going down. for example, I want them to be able to see the following.

You will be redirected in 5 seconds.

The user should be able to see the count going down from 5 to 4 to 3 to 2 to 1 and then they are redirected.

I can get the page to redirect after 5 seconds but I want the user to be able to see it count down.

Thanks in advance for your help

Edited by puk: To give more clarity

7 Years
Discussion Span
Last Post by Taywin

The code below just to show you how to do it (approximate time). I do not want to complicate the code, so it should be working in most cases.

<script type="text/javascript">
function redirectTo(url, timerID) {
  var el=document.getElementById(timerID)
  if (el) {  // element exist
    el.innerHTML = 5  // start with 5 seconds

function runTimer(url, timerID) {
  var el=document.getElementById(timerID)
  if (el) {
    var time = parseInt(el.innerHTML,10) - 1
    if (time>0) {  // not 0 yet, keep running
      el.innerHTML = time
    else {  // redirect
      window.location = url

  <input type="button" value="Redirect" onclick="redirectTo('a_URL_to_be_redirected_to', 'showTimer')">
  <br />
  <div id="showTimer"></div>

Edited by Taywin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.