Questions tagged [session-storage]

Session Storage is an HTML 5 browser standard to enable storage and retrieval of simple data on the client. This is a global object (sessionStorage) that maintains a storage area that's available for the duration of the page session. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated.

Session Storage enables storage and retrieval of key-value-pairs in the browser, that endure only as long as the session.


The sessionStorage Object

The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the browser window.

Only plain-text values can be stored. Arrays, hashes, numbers, strings and booleans can be stored by using JSON.stringify(value). Then, to get the original value when reading the value, use JSON.parse(stringified_value).

Example

if (sessionStorage.clickcount) {
    sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;
} else {
    sessionStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " +
sessionStorage.clickcount + " time(s) in this session."; 

Resources

906 questions
768
votes
11 answers

What is the difference between localStorage, sessionStorage, session and cookies?

What are the technical pros and cons of localStorage, sessionStorage, session and cookies, and when would I use one over the other?
Pank
  • 13,800
  • 10
  • 32
  • 45
715
votes
11 answers

HTML5 Local storage vs. Session storage

Apart from being non persistent and scoped only to the current window, are there any benefits (performance, data access, etc) to Session Storage over Local Storage?
jpkeisala
  • 8,566
  • 7
  • 30
  • 39
230
votes
8 answers

browser sessionStorage. share between tabs?

I have some values in my site which I want to clear when the browser is closed. I chose sessionStorage to store those values. When tab is closed they are indeed cleared, and kept if the user presses f5; But if the user opens some link in a different…
Vladimir Gordienko
  • 3,260
  • 3
  • 18
  • 25
192
votes
10 answers

Save Javascript objects in sessionStorage

SessionStorage and LocalStorage allows to save key/value pairs in a web browser. The value must be a string, and save js objects is not trivial. var user = {'name':'John'}; sessionStorage.setItem('user', user); var obj = sessionStorage.user; //…
Ferran Basora
  • 3,097
  • 3
  • 19
  • 13
56
votes
2 answers

How large is HTML5 session storage?

Although the size of localStorage has been addressed in detail and there is a online test for it, I was wondering what the maximum size of sessionStorage is for the common browsers?
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
55
votes
10 answers

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…
northernMonkey
  • 1,273
  • 4
  • 12
  • 24
29
votes
5 answers

Local Storage, Session storage, Web storage, web database and cookies in HTML5

What is the difference between these concepts, and when should I use one in particular? Does this listing also contain different names for the same general concept? HTML5 local storage HTML5 session storage HTML5 web storage HTML5 web…
texai
  • 3,696
  • 6
  • 31
  • 41
29
votes
3 answers

On a browser, sessionStorage in Safari's Private Browsing does not work the same as Chrome's Incognito Mode and Firefox's Private Window?

It seems that for sessionStorage, it works differently on Chrome's Incognito Mode vs Safari's Private Browsing and Firefox's Private Window? I can find something on http://www.webdirections.org/blog/webstorage-persistent-client-side-data-storage/…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
26
votes
3 answers

Implement session storage in an Angular 8 application

I am building a movie application to aid my learning. I will like to know how to capture and save the number of clicks on button in session storage. I have been able to get the click working. It increases and display number of click on each button,…
Darotudeen
  • 1,914
  • 4
  • 21
  • 36
25
votes
3 answers

Can Session storage / local storage be disabled and Cookies enabled?

For most modern browsers, is it possible to have session or local storage disabled while cookies are enabled? Or does the disabling of cookies also, automatically, disable the use of session / local storage?
Randy Minder
  • 47,200
  • 49
  • 204
  • 358
19
votes
3 answers

Share data across e-book pages

I want to have a quiz at the end of a chapter in my fixed layout epub3 e-book. This quiz will stretch across a number of pages and will be multiple choice in nature. Each question will consist of the question itself and four options, each with a…
Baz
  • 12,713
  • 38
  • 145
  • 268
19
votes
5 answers

Javascript: Retrieve all keys from sessionStorage?

Is it not posssible to retrieve all keys/objects that I stored in sessionStorage (or localStorage)? If I have done sessionStorage.name = 'John' and sessionStorage.city = 'New York', isn't there a way to get a list that shows the keys name and city?
TheStoryCoder
  • 3,403
  • 6
  • 34
  • 64
19
votes
2 answers

How to store an auth token in an Angular app

I have an Angular application (SPA) that communicates with a REST API server and I'm interested in finding out the best method to store an access token that is returned from an API server so that the Angular client can use it to authenticate future…
16
votes
2 answers

sessionStorage in iframe

I'm going to have several iframes on my page and I'm going to quite intensively use sessionStorage inside them. What I'm curious about is if I will have separate storages or one shared for all iframes? How do the size limits apply?
strannik
  • 1,595
  • 1
  • 13
  • 22
15
votes
8 answers

Why would you ever use asp.net's ViewState storage object over the Session storage object?

Other than because session storage is session-global to more than one page, why would you ever want to use the viewstate to hold values? It seems kind of ridiculous to send any kind of information other than a few small query string like values,…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
1
2 3
60 61