When is sessionStorage actually cleared?

I have javascript that validates an object in sessionStorage and uses it to populate an input field. I use this to help users on my site if they leave the form incomplete and either leave or try to submit the form after the expiration of their session.

I understand that sessionStorage is NOT tied to a server session, it is connected to the browser, so it does not matter whether I have a new session on the server or not.

This was supported when I tested it a few months ago. However, it seems that this is no longer the case, and when I clear my session cookie and reload my page, my storage session is also cleared. This uses both Chrome and Firefox.

I do not want to use localStorage, as this can cause problems with shared computers, while sessionStorage will be destroyed when closing browser windows.

JS to get the value of my stored object

JSON.parse(sessionStorage.getItem("draftPost") || null); 

Js to save value

 $("#wallText").on("change",function(){ sessionStorage.setItem("draftPost",JSON.stringify(draftPost)); }); 
+6
source share
2 answers

Something to keep in mind with sessionstorage on a mobile safari.

As stated in the mozila.org document mentioned by timolawl:

Note. Starting with iOS 5.1, Safari Mobile stores local storage data in a cache folder, which is subject to periodic cleaning, at the request of the OS, usually if the space is short.

This cleanup happens too often on a mobile safari, and all sessionstorage variables are destroyed for all open tabs.

For example, by opening 5 tabs and then loading a new page with a lot of java and css, you can clear it by destroying all sessionstorage variables.

However, localstorage variables are preserved.

In addition, on safari (I believe both on the desktop and on the mobile phone) closed viewing will prevent the use of either localstorage or sessionstorage.

+4
source

Session storage is cleared when the browser is closed. It is saved on page reload and restored. See: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

+1
source

All Articles