简体   繁体   中英

javascript countdown timer with cookies

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?

Take a look at this SO answer:

javascript-cookie-timeout-with-countdown-timer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM