here is a piece of code im working with,
im trying to keep the timer from starting over on page refresh that the user is on. the time and redirect i can worry about later on, but getting localstorage to work is very important.
<script type='text/javascript'>
window.onload=function(){
function countdown( elementName, minutes, seconds )
{
var element, endTime, hours, mins, msLeft, time;
function twoDigits( n )
{
return (n <= 9 ? "0" + n : n);
}
function updateTimer()
{
msLeft = endTime - (+new Date);
if ( msLeft < 1000 ) {
element.innerHTML = "0:00";
window.alert("addfgdg");
// redirect to google after 5 seconds
window.setTimeout(function() {
window.location.replace = 'http://www.google.com';
}, 5000);
} else {
time = new Date( msLeft );
hours = time.getUTCHours();
mins = time.getUTCMinutes();
element.innerHTML = (hours ? hours + ':' + twoDigits( mins ) : mins) + ':' + twoDigits( time.getUTCSeconds() );
setTimeout( updateTimer, time.getUTCMilliseconds() + 500 );
}
}
element = document.getElementById( elementName );
endTime = (+new Date) + 0300 * (60*minutes + seconds) + 500;
updateTimer();
}
countdown( "countdown", 1, 5 );
}//]]>
</script>
i tried my best doing so but get blank results,
any help appreciated.