Reputation: 3581
I want to refresh a web page and retain the value of the variable (created in javascript) when the page is reloaded.
for eg: var cnt = 5; cnt++;
I want the value of 'cnt' to be 6 even after I refresh a page. How can I do it?
Upvotes: 0
Views: 1822
Reputation: 1224
I don't see how you can do this, except by using cookies or session.
Upvotes: 1
Reputation: 1892
Or put them after the hash tag.
var cnt=5; -> refresh page with adding hash to the url:
http://domain.com/index.php#cnt=5
then extract it after reload...
Google: window.location.hash
Upvotes: 0
Reputation: 7253
Store the values in cookies or use browser local storage.
Read this for more info http://www.w3schools.com/html5/html5_webstorage.asp
Upvotes: 3