Reputation: 31
I try to persist data in the local storage, with localStorage.setItem('key','value')
and locaStorage.getItem('key')
but as soon as I close the browser everything is deleted, Local Storage is not supposed to be persistent ? :(
Thank you for your help :)
Ps. I use a html file with some javascript, do we need a web server or domain for persist ?
Upvotes: 1
Views: 142
Reputation: 10601
When you open a webpage locally with the file://
protocol the browser won't associate the next opening session with the last one. So it is not possible to use localstorage with local file persistently.
Upvotes: 1
Reputation: 23
Try JSON.stringify-ing your 'value', eg:
localStorage.setItem("key", JSON.stringify(value));
and
JSON.parse(localStorage.getItem("key"));
when getting your values.
Upvotes: 0