user1074247
user1074247

Reputation: 1

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

i have countdown timer in java script ,i want to retain the countdown time even when the page is refreshed can you please suggest me what direction i have to follow

Upvotes: 0

Views: 471

Answers (2)

Rob W
Rob W

Reputation: 348992

Don't use cookies, because they add unnecessary overhead to your page requests.

Use localStorage instead (compatibility table (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');

Upvotes: 1

David Houde
David Houde

Reputation: 4778

Use a cookie to set a timestamp, and then reference the timestamp in future page loads.

Upvotes: 0

Related Questions