javascript countdown timer with cookies

Posted by jwesonga on Stack Overflow See other posts from Stack Overflow or by jwesonga
Published on 2010-06-14T09:35:13Z Indexed on 2010/06/14 9:42 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I have a countdown timer that will show a target amount to be fundraised like USD1000000 and slowly count backwards to zero over a period of days. I got this snippet:

$(function() 
{            
var cnt = 75000000;            
var count = setInterval(function() 
{                
if (cnt > 0) 
{                    
$('#target').html("<span>KSHS</span><strong>" + cnt + " Target </strong>");                    
cnt--;                
}                
else 
{                    
clearInterval(count);                    
$('#target').html("<strong> Target Achieved! </strong>");                
}            
}, 4000);        
});     

The only problem is that everytime you refresh the page the counter starts again which essentially means it will never end.

I'd like it that a when a user revisits/refreshes the page the counter persists and continues. I've read that javascript cookies can be used for this, just don't know how to implement them, any help?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about cookies