Reputation: 61
so i have this piece of code im looking to alter or just add to,
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 = "countdown's over!";
} 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) + 1000 * (60*minutes + seconds) + 500;
updateTimer();
}
countdown( "countdown", 1, 5 );
while the timer is going, lets say if the person refreshes the page i dont want the timer to restart i want it to continue going.
i would rather a message popup rather that it be included in the html if that makes any sense.
5 seconds after the time is up i would like it to redirect to a different page.
im not js savvy sorry for the pain in the neck questions.
Upvotes: 0
Views: 60
Reputation: 6419
window.location.replace("http://example.com");
Upvotes: 0
Reputation: 207
Upvotes: 2