This might be a bit general but, I'm wondering where are js variables stored? And are they kept when you click into new pages or every time the data is reset?
2 Answers
They are reset every time you refresh.
There are multiple ways to persist them between reloads. e.g.
- Webstorage http://en.wikipedia.org/wiki/Web_storage
- cookies
- You save them to the database and load them into a session. Then render server side.
For all of these methods you would need to persist these (generally due to some user interaction) and load these on page reload etc. It does not happen automatically, you have to explicitly do so.
6 Comments
OneZero
What if I want to keep some variables?
kieran
you'll need to roundtrip them to the server; consider using sessions or cookies for storing persistent state, e.g. the document.cookie api
MikeSmithDev
@OneZero Web Storage, cookies, or your own DB.
Kiarash
It depends what server side technology you are using if it is ASP.Net you can also store it on the page viewstate as well
MikeSmithDev
@Kiarash I'm assuming this isn't a simple postback scenario.
|
They stored in client memory and as Basarat mentioned they gone on each postbask or refresh
1 Comment
Kiarash
the whole description was not there when I commented at that time the sentence was just this "They are reset every time you refresh."