I have this problem and i dont know if there is way that the countdown time will continue even the page is refresh or if the page is refresh there is an alert box saying "Are you sure you want to leave the page?" and if Ok it will redirect to another page?
Here is my ajax script in countdown
<script type="text/javascript">
window.onload = function()
{
countDown('timeLimit', 'sample.html', 60);
}
function countDown(elID, output, seconds)
{
var elem = document.getElementById(elID),
start = new Date().getTime(), end = start+seconds*1000,
timer = setInterval(function() {
var now = new Date().getTime(), timeleft = end-now, timeparts;
if( timeleft < 0) {
document.location.href = output;
clearInterval(timer);
}
else {
timeparts = [Math.floor(timeleft/60000),Math.floor(timeleft/1000)%60];
if( timeparts[1] < 10) timeparts[1] = "0"+timeparts[1];
elem.innerHTML = "Time left: "+timeparts[0]+":"+timeparts[1];
}
} ,250); // the lower this number, the more accurate the timer. 250 recommended
}
</script>
How to continue that time even the page is refresh or redirect to another page when the page is refresh?
Please help..im new in javascript..:(