View Full Version : Countdown script on site load?
Rezo
May 2nd 2009, 11:35 pm
Dear friends,
I need your help :) I need a script that starts the countdown on site load.
For example, user loads the page and I need a countdown from 5 minutes to 0 minutes and 1 second, and I need it do be displayed on the site interactively.
I hope you understood. Thanks for your help in advance.
Regards,
Radu
camjohnson95
May 4th 2009, 2:52 am
<div id="divTimer"></div>
<script type="text/javascript">
var t = 20;
var divT = document.getElementById("divTimer");
window.onload = countdown;
function countdown() {
if(t > 0) {
divT.innerHTML = parseInt(t/60) + " minutes, " + (t % 60) + " seconds";
t = t - 1
setTimeout("countdown()", 1000);
}
}
</script>
camjohnson95
May 4th 2009, 3:12 am
or to make it more 'clock-like':
<div id="divTimer"></div>
<script type="text/javascript">
var t = 300;
var divT = document.getElementById("divTimer");
var d = new Date();
window.onload = countdown;
function countdown() {
if(t > 0) {
d.setMinutes(parseInt(t/60));
d.setSeconds(t%60);
divT.innerHTML = d.toTimeString().substr(3,5);
t = t - 1
setTimeout("countdown()", 1000);
}
}
</script>
Rezo
May 4th 2009, 6:39 am
or to make it more 'clock-like':
<div id="divTimer"></div>
<script type="text/javascript">
var t = 300;
var divT = document.getElementById("divTimer");
var d = new Date();
window.onload = countdown;
function countdown() {
if(t > 0) {
d.setMinutes(parseInt(t/60));
d.setSeconds(t%60);
divT.innerHTML = d.toTimeString().substr(3,5);
t = t - 1
setTimeout("countdown()", 1000);
}
}
</script>
Hey,
thanks alot.
Is this the full including the code to display it?
Regards,
Radu
JavaScriptBank.com
May 4th 2009, 5:56 pm
you can use some counter JavaSctripts (http://www.javascriptbank.com/title=counter) from my site
camjohnson95
May 5th 2009, 10:17 pm
yes, the timer will be displayed wherever the line:
<div id="divTimer"></div>
is placed... just make sure that the script is placed after the div.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.