Currently can achieve JS Countdown, but, page a refresh, countdown either directly stop, or directly start again.
so that's the problem?
How to control JS, even if you refresh the page, the countdown is continuous.
Trouble everyone passing by the small partner, do a favor. Thank you!
Reply content:
Currently can achieve JS Countdown, but, page a refresh, countdown either directly stop, or directly start again.
So that's the problem?
How to control JS, even if you refresh the page, the countdown is continuous.
Trouble everyone passing by the small partner, do a favor. Thank you!
Start countdown time to get local time, deposit cookie or localstorage, refresh after read start time and now time want to reduce
Check out the service Worker
Each refresh is a new function running environment and cannot know the state before the refresh. The start time of your timer can only be obtained from the background or calculated based on the current time.
Using cookies or Localstorage,
See a specific answer I wrote.
Http://stackoverflow.com/a/38 ...
3 js:$("#end_time").val()
should be able to read the meaning
When the countdown starts, save the end time to Localstorage, refresh the page to read the Localstorage value and calculate the countdown
Recently the old people asked the countdown question, before writing a simple, the landlord can see
Find a countdown code for every Tuesday
Your countdown start time do not use js
to get the client time, use php
to get the server time to give a js
try
Write a local storage countdown and it's OK.
To achieve a countdown function, first you have to have a fixed end time, the normal logic implementation:
Pass the end time into a countdown method, use the end time minus the current time, get the remaining time, and execute once in a second. The current time will increase, then the remaining time will be reduced accordingly.
So where does the fixed end time come from. 1, the code inside write dead Time 2, back end return time 3, local storage. As long as you get the fixed end time, the countdown will not start from scratch. Interrupts are only seen in the event of a countdown or code error. I wrote a multiple countdown to the simultaneous existence of the page link description
If you want the front-end control can only take advantage of cookie/web storage such as browser storage, so that the same browser does not clear the cache can achieve your needs, if necessary even if the change of the browser will remain unchanged only back-end return time
"Send SMS verification, post button countdown, prevent refresh Countdown expired"
Application scenarios, in the development of "Send SMS Verification" function, to solve a problem, to prevent malicious or frequent SMS verification code issues. The general principle is "when you click the Send button, send an AJAX request to the server to send SMS verification code, the success of the Send button is set to not click, and call, the original link: https://segmentfault.com/a/11 ...