Excuse me, I want to ask how to make javascript countdown doesn't reset when page refresh??
thank you in advance
Excuse me, I want to ask how to make javascript countdown doesn't reset when page refresh??
thank you in advance
The scope of JavaScript code is per page so refreshing the page is like making the code start again - like switching it off and on again.
So if you want to persist some value - ie the state of your counter - then you will need to store it somewhere and load it up again when the page is loaded.
The counter needs to be per user of course otherwise everyone will get the same value! So one option could be a cookie and another could be to store it on a server somewhere but that depends what technologies you are using, is your user signed in etc.
Reading and writing cookies with JavaScript - http://www.w3schools.com/js/js_cookies.asp
Hope that helps.
Or load your pages dynamically via AJAX (plus HTML5 History API) in a container (div) and place the counter oustide this container.
Look at this demo. Audio player keeps on playing and URL changes while navigating between content. This library really rocks!
Hi,
If it is a countdown you can use Date() since the countdown is from a specific time then when you refresh the page it will show the countdown according to the time left.
Some websites which may help:
https://mindgrader.com/tutorials/1-how-to-create-a-simple-javascript-countdown-timer
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.