Saturday, 2 October 2021

When is sessionStorage actually cleared?

I have some javascript that checks for an object in sessionStorage, and uses it to refill an input field. I use this to help users on my site if they leave the form unfinished and either navigate away or try to submit the form after their session has expired.

My understanding is that sessionStorage is NOT linked to a server session, it is linked to the browser, so whether I have a new session on the server or not is irrelevent.

This was supported when I was testing this initially a few months ago. However, it seems ot no longer be the case, and when I clear my session cookie and reload my page, my sessionStorage is also cleared out. This is using both Chrome and Firefox.

I don't want to use localStorage as that could cause issues with shared computers, whereas sessionStorage will be wiped out when the browser windows is closed.

JS to get the value of my stored object:

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

JS to save the value:

$("#wallText").on("change", function(){
    sessionStorage.setItem("draftPost", JSON.stringify(draftPost));
});


from When is sessionStorage actually cleared?

No comments:

Post a Comment