Timer refreshes after browser page is reloaded - Javascript

China☆狼群 提交于 2019-11-29 17:35:00

You'll probably want to save to the localStorage every time your timer ticks. Something like this:

localStorage.setItem('timerValue', timerValue); // assume timerValue is defined

When the user opens the page, you'll need to retrieve said item:

var time = localStorage.getItem('time');

Edit:

I think your problem might be with the following code:

if (localStorage.seconds) {
  seconds = localStorage.seconds;
}

You're checking whether localStorage has a property called seconds before setting it, but the first time you try to save seconds this property will always be undefined.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!