Web Analytics Made Easy -
StatCounter Countdown script to zero - CodingForum

Announcement

Collapse
No announcement yet.

Countdown script to zero

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Countdown script to zero

    Hi all..
    I want to put script on my page which count number down from 10 to 0 then redirect to main page automatically.

    Is there any JS to doing this?
    I've do search all arround the net but still found nothing.

    Thank you..

  • #2
    you probably want to control the speed of the countdown too....

    Code:
    var g_interval = 10;
    function countDownRedir()
    {
      if (--g_interval == 0)
      {
        document.location = "http://www.newurl.com";
        clearInterval(g_interval);
      }
    }
    
    var g_interval = setInterval(countDownRedir, 1000);

    Comment


    • #3
      Why not a simple HTML solution?... Put this meta tag in the HEAD section of your page:

      Code:
      <meta http-equiv="refresh" content="10;url=http://www.yourdomain.com/yourmainpage.html">
      Last edited by Kor; Sep 26, 2006, 12:27 PM.
      KOR
      Offshore programming
      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      Comment


      • #4
        That's a great simple solution to the problem.

        The reason to use the javascript solution is to do more than simply redirect after 10 seconds. For example, perhaps the OP would like to display a timer. All you'd have to do is add the extra code for displaying the timer.

        But yeah, the meta refresh, easiest way to accomplish the timed redirect.

        Comment


        • #5
          wow, what a great solution.. thanks to all who have reply my thread, especialy to Beagle for nice JS coding..

          Thank you so much all...

          kind regards.

          Comment


          • #6
            Actually, I just looked, my code is broken. I'm so dumb.

            Change the variable g_interval on lines 7 and 11 to g_countdownInterval, or something else, like so:

            Code:
            var g_interval = 10;
            function countDownRedir()
            {
              if (--g_interval == 0)
              {
                document.location = "http://www.newurl.com";
                clearInterval(g_countdownInterval);
              }
            }
            
            var g_countdownInterval = setInterval(countDownRedir, 1000);
            Sorry about that, total brain fart.

            Comment


            • #7
              thanks Beagle.
              Finally, i've got the right code..
              'cause the prev code doesn't works.
              thanks..

              Comment

              Working...
              X