简体   繁体   English

即使刷新页面也如何保持倒数计时器的时间

[英]How to retain the time of the countdown timer even when the page is refreshed

我在Java脚本中有倒数计时器,即使页面刷新后,我也想保留倒数时间,能否请您建议我必须遵循的方向

Don't use cookies, because they add unnecessary overhead to your page requests. 不要使用cookie,因为它们会给您的页面请求增加不必要的开销。

Use localStorage instead ( compatibility table ( polyfills )): 改用localStorage兼容性表polyfills )):

var countdowntimervalue = 100;                            // Some variable
localStorage.setItem('timer_value', countdowntimervalue); // <-- Set the value

To get the value at a later point use: 要在以后获取值,请使用:

var saved_value = localStorage.getItem('timer_value');

使用cookie设置时间戳,然后在将来的页面加载中引用该时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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