1

when I refresh the browser all the values stored in localStorage are gone. is there a way to prevent the browser to delete it?

    localStorage.setItem("loggedIn", false);

thanks

Felix
  • 4,808
  • 9
  • 45
  • 130
  • thanks for not explaining why downvoting! – Felix Aug 31 '17 at 11:38
  • Are you in an incognito window? localStorage *is* persistent, that shouldn't be happening by default... Perhaps this question will help: https://stackoverflow.com/questions/9948284/how-persistent-is-localstorage – BenM Aug 31 '17 at 11:38
  • no I'm not in incognitio mode ... – Felix Aug 31 '17 at 11:38
  • added an example above – Felix Aug 31 '17 at 11:39
  • I have added some explanation on it – Ankit Agarwal Aug 31 '17 at 11:42
  • 1
    Are you sure it's getting deleted, have you looked in the Inspector and viewed localStorage?.. Also I assume your doing `getItem()` as well? – Keith Aug 31 '17 at 11:52
  • @Felix please don't whine about downvotes, you give us a bad name ;) – Félix Gagnon-Grenier Aug 31 '17 at 12:06
  • @FélixGagnon-Grenier I don't whine, but If somebody do a downvote then there should be an explanation – Felix Aug 31 '17 at 13:02
  • Possible duplicate of: [When is localStorage cleared?](https://stackoverflow.com/questions/8537112/when-is-localstorage-cleared) – Rory McCrossan Aug 31 '17 at 13:14
  • @Felix No. There is absolutely no requirement, recommendation or anything that encourages people to explain downvotes. Are you aware of the meta portion of the site? Start [reading here](https://meta.stackoverflow.com/a/285777/576767). The general consensus about explaining downvotes is that we have strictly no reason to do it. – Félix Gagnon-Grenier Aug 31 '17 at 13:27
  • when You downvote a question there is a popUp or hint which reminds you to make a comment ... only a downvote does not improve anything – Felix Aug 31 '17 at 13:44

1 Answers1

2

localStorage is also known as Web Storage, HTML5 Storage, and DOM Storage.

localStorage is similar to sessionStorage, except that data stored in localStorage has no expiration time, but sessionStorage gets cleared when the browsing session ends (i.e. when the browser is closed).

localStorage is available on all browsers, but persistence is not consistently implemented. Furthermore localStorage can be cleared by user action.

In Firefox, localStorage is cleared when these three conditions are met:

  1. user clears recent history,

  2. cookies are selected to be cleared

  3. time range is "Everything"

In Chrome, localStorage is cleared when these conditions are met:

  1. clear browsing data,

  2. "cookies and other site data" is selected,

  3. timeframe is "from beginning of time".

In IE, to clear localStorage:

  1. Tools-->Internet Options,

  2. General tab,

  3. delete browsing history on exit

In Safari:

  1. Click Safari

  2. Preferences

  3. Select the Privacy tab

  4. Click Remove all website data

Ankit Agarwal
  • 28,439
  • 5
  • 29
  • 55
  • 1
    Please vote to close as a dupe instead of plagiarising content from [another answer](https://stackoverflow.com/a/37105645/519413) – Rory McCrossan Aug 31 '17 at 13:13