Jquery/Javascript timer that doesn't restart on refresh -
this first question on :)
i need timer in jquery or javascript countdown 15 minutes, , show close button. also, when user refreshes page should not reset, either continue stopped or finish countdown not depending on whether user came back, i.e. if user returns after 16 minutes, see message , close button. suggestions?
thank much!
here localstorage solution this. read comments, can manipulate timer, easily
this timer won't countdown when user not on page. remembers state of counter when leaves. know basic idea. can make date.gettime() kind of scenario improve :p
var updatetimer = function() { timer = localstorage.getitem('timer') || 0; if ( timer === 0 ) { $("div#timer").html("timer unset"); } else { timer--; localstorage.setitem('timer', timer); $("div#timer").html(timer); } }; $(function() { setinterval(updatetimer, 1000); $("#start").click( function() { localstorage.setitem('timer', 500); }); });
Comments
Post a Comment