Reputation: 831
I have written the following code for a Javascript timer with a few validations.
function timedcounter(){
time=time+1;
t = setTimeout(function(){ timedcounter() }, 1000);
display(time);
}
function starttimer() {
var autotask=document.getElementById("Tasks").value
if(autotask=="") {
$("#errormsg2").show();
} else {
if(!timer_is_on){
add_row_flag=1;
var value=document.getElementById("startstopbutton").value
if(value=="Start") {
timer_is_on=1;
value="Stop";
document.getElementById("startstopbutton").innerHTML="Stop"
$("#errormsg2").hide();
timedcounter();
}
} else {
add_row_flag=0;
stoptimer();
}
}
}
function stoptimer(){
clearTimeout(t);
timer_is_on=0;
document.getElementById("startstopbutton").innerHTML="Start"
document.getElementById("disptime").value=null;
finaltime(time);
time=-1;
}
I wanted to know is there any way to keep the timer going even after the user closes the browser, as in when he reopens the webpage timer should show the time elapsed since he started the timer.
Upvotes: 0
Views: 613
Reputation: 18556
You have three options:
Upvotes: 1