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)); });
Introduction to JavaScript sessionStorage The sessionStorage object stores data only for a session. It means that the data stored in the sessionStorage will be deleted when the browser is closed. A page session lasts as long as the web browser is open and survives over the page refresh.
Use SessionStorage instead. It gets cleared off whenever the tab is closed.
The sessionStorage object stores data for only one session. (The data is deleted when the browser is closed).
Web storage objects localStorage and sessionStorage allow to save key/value pairs in the browser. What's interesting about them is that the data survives a page refresh (for sessionStorage ) and even a full browser restart (for localStorage ).
Session storage is cleared when the tab closes. It persists over page reloads and restores. See: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
- Whenever a document is loaded in a particular tab in the browser, a unique page session gets created and assigned to that particular tab. That page session is valid only for that particular tab.
- A page session lasts as long as the tab or the browser is open, and survives over page reloads and restores.
- Opening a page in a new tab or window creates a new session with the value of the top-level browsing context, which differs from how session cookies work.
- Opening multiple tabs/windows with the same URL creates sessionStorage for each tab/window.
- Duplicating a tab copies the tab's sessionStorage into the new tab.
- Closing a tab/window ends the session and clears objects in sessionStorage.
Note that the duplication of the tab does not seem to work in Firefox, it does however in Chrome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With