简体   繁体   English

(javascript)倒计时在页面刷新时不重新启动?

[英]a (javascript) countdown that doesn't restart at page refresh?

i was wondering if there is any solution for implementing a javascript counter that doesn't reset at page refreshm but it continues counting until the set time passes. 我想知道是否有实现javascript计数器的解决方案,该计数器不会在页面刷新时重置,但会继续计数直到设置的时间过去。

What do you know about it? 你怎么知道的?

thank you 谢谢

You could store the current countdown timer count in a cookie (you would do that every time the timer changes). 您可以将当前的倒数计时器计数存储在cookie中(每次计时器更改时都将这样做)。 And then when the page loads (or refreshes) check for the value of that cookie first, and if it is set use that value as the starting point of the countdown counter. 然后,当页面加载(或刷新)时,首先检查该cookie的值,如果已设置,则使用该值作为倒数计数器的起点。

You will need to store its state somewhere, either in a cookie or serverside. 您将需要将其状态存储在Cookie或服务器端的某个位置。

On each page load, the code will need to check its state and adjust its countdown accordingly. 在每次加载页面时,代码都需要检查其状态并相应地调整其倒计时。

You can use localStorage or cookies to store your current counter value. 您可以使用localStorage或cookie存储当前的计数器值。 Here's an example: http://jsfiddle.net/ArtBIT/KsYE4/ 这是一个示例: http : //jsfiddle.net/ArtBIT/KsYE4/

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

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