View Full Version : Countdown script to zero
redfroc
09-26-2006, 01:20 PM
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..
Beagle
09-26-2006, 02:48 PM
you probably want to control the speed of the countdown too....
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);
Why not a simple HTML solution?... Put this meta tag in the HEAD section of your page:
<meta http-equiv="refresh" content="10;url=http://www.yourdomain.com/yourmainpage.html">
Beagle
09-26-2006, 05:27 PM
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.
redfroc
10-02-2006, 01:41 PM
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.
Beagle
10-02-2006, 02:25 PM
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:
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.
redfroc
10-30-2006, 11:57 AM
thanks Beagle.
Finally, i've got the right code..
'cause the prev code doesn't works.
thanks.. :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.