admin管理员组文章数量:1336394
I want to set a cookie with javascript. Easy enough. Lets say I set it for 15 minutes.
How would I make a count down timer show to show when the cookie expires? And even if they left the page I would want it to keep counting and when they e back to the page it would still have been counting down.
Sorry for the poor explanation. But I'm fairly sure its possile.
Thanks
I want to set a cookie with javascript. Easy enough. Lets say I set it for 15 minutes.
How would I make a count down timer show to show when the cookie expires? And even if they left the page I would want it to keep counting and when they e back to the page it would still have been counting down.
Sorry for the poor explanation. But I'm fairly sure its possile.
Thanks
Share Improve this question asked Sep 28, 2009 at 15:51 Ben ShelockBen Shelock 21k26 gold badges97 silver badges126 bronze badges1 Answer
Reset to default 5Store the time stamp of now + 15 minutes within a cookie if there is no cookie. Write a simple script that checks the difference between now and the timestamp every second.
Edit: sample code
// 200 seconds countdown
var countdown = 200;
//current timestamp
var now = Date.parse(new Date());
//ready should be stored in your cookie
var ready = Date.parse(new Date (now + countdown * 1000)); // * 1000 to get ms
//every 1000 ms
setInterval(function()
{
var sec = ( ready - Date.parse(new Date()) )/1000;
document.title = sec + " seconds left";
},1000);
本文标签: Javascript Cookie Timeout With Countdown TimerStack Overflow
版权声明:本文标题:Javascript Cookie Timeout With Countdown Timer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742391652a2466107.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论