Is there a way to have JavaScript hold any variables through a reload?
If the user hits the reload button, is there any state that is kept by JavaScript, once a page is reloaded?
Is there a way to have JavaScript hold any variables through a reload?
If the user hits the reload button, is there any state that is kept by JavaScript, once a page is reloaded?
Share edited May 29, 2012 at 23:22 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked May 29, 2012 at 22:49 user656925user656925 3- 1 This is now the third time I've had to correct your spelling of javascript in the past few days. Please take more care when selecting tags! – Charles Commented May 29, 2012 at 23:22
- Indeed, you gained the ability to create new tags once you hit 1500 reputation. – Charles Commented May 30, 2012 at 17:04
- Possible duplicate of Global Variable usage on page reload – Liam Commented Jun 1, 2017 at 14:52
3 Answers
Reset to default 5Suggestions
- Cookie
- HTML 5 Web Storage https://www.w3schools./html/html5_webstorage.asp
Either way, you'll need to write your own read/write methods to store your state.
You will have to utilize cookies to maintain your state. If you're using jQuery I sugest you look into jQuery Cookie:
https://github./carhartl/jquery-cookie
Hope this helps you!
small data (2KByte) can be stored in the URL suffix
fragment ID: //host/path#fragment-id
query string: //host/path?query-string
the fragment-id-method is used here:
http://xkcd-map.rent-a-geek.de/
on every dragend-event, the URL is changed
to reflect the current position on the map
special chars mut be urlencode-d
related: hot reloading, reloadable code, figwheel.clj, react.js hot loader