Hey guys, here is a countdown script I wrote that doesn't use JQuery.
It's probably no where near perfect because I suck at Maths AND javascript, but it works and you won't have to include jquery on your landers.
<script type="text/javascript">
// Set how many seconds to count down, milli stays at 1000
var seconds = 59;
var milli = 1000;
var timeoutval;
function Timer() {
timeoutval = setTimeout(Timer, 10);
if (seconds < 0) {
// Stop the timeout function
clearTimeout(timeoutval);
// Do Something like close window or redirect page.
alert('hola');
}
else {
// if the milli seconds is below zero, de-increment(is that even a word??) the second and reset milliseconds
if (milli < 0) {
seconds--;
milli = 1000;
}
else {
// Display the countdown
DisplayCountdown();
}
// de-increment milli by 10, 10 seemed to work the best
milli = milli - 10;
}
}
function DisplayCountdown() {
// Fill a span tag with the id of timer
var timer = document.getElementById('timer');
// The code below pads the millisecond string so the value doesn't jump around
if (milli < 10) {
timer.innerHTML = seconds + '.00' + milli;
}
else if (milli < 100) {
timer.innerHTML = seconds + '.0' + milli;
}
else {
timer.innerHTML = seconds + '.' + milli;
}
}
Timer();
</script>
<p>This offer will close in <span id="timer"></span> seconds</p>
Oh, that's just beautiful. You'd get 100 thanks from me if I could put them in there.
Thanks for putting clear comments at each step.
Thanks Liane!
I just made an update to the code (Added a way to shut off the ticks as it wasn't letting the redirect happen).
Thanks so much~!! Ive been looking for this for awhile.