Questions tagged [sessionstorage]

The sessionStorage object stores the data for only one session. The data is deleted when the user closes the browser window.

See also


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

151 questions
114
votes
2 answers

Scope of sessionStorage and localStorage

I read some documentation on sessionStorage and localStorage, but I don't understand what the scope is: the domain, a specific page? For example, if I have the following…
Christophe
  • 27,383
  • 28
  • 97
  • 140
80
votes
4 answers

Where the sessionStorage and localStorage stored?

Where are sessionStorage and localStorage stored on the client's computer? Could you tell me the path?
OammieR
  • 2,800
  • 5
  • 30
  • 51
26
votes
3 answers

How do I bind event to sessionStorage?

I can successfully bind an event for a change to localStorage (using jquery): $(window).bind('storage', function(e) { alert('change'); }); localStorage.setItem('someItem', 'someValue'); If I use sessionStorage, the event will NOT fire: …
Tesco
  • 385
  • 1
  • 3
  • 6
20
votes
5 answers

Is there a way to remove all sessionStorage items with keys that match a certain pattern?

Lets say my sessionStorage contains three objects who's keys are foo, foobar, and baz. Is there a way that I can call .removeItem or somehow delete all items in sessionStorage who's keys match foo? In this example I'd be left with only the item…
Jesse Atkinson
  • 10,586
  • 13
  • 42
  • 45
16
votes
1 answer

HTML5 sessionStorage limits?

A few questions regard HTML5's sessionStorage: Does the 5MB limit on localStorage include sessionStorage? (ie. is it really a 5MB limit on the WebStorage API) If not does sessionStorage have a maximum size limit similar to localStorage? I found…
Cubed Eye
  • 5,581
  • 4
  • 48
  • 64
15
votes
2 answers

Duplicate Tab copying sessionStorage in Chrome

When a tab is duplicated in Chrome, is sessionStorage also duplicated? I noticed that in IE it is not.
user3254314
  • 151
  • 1
  • 3
14
votes
5 answers

How to prevent sessionStorage being inherited when using target="_blank"/window.open() to open a new window/tab?

On a tab with url http://foo.com/ I set a sessionStorage item thus- sessionStorage.bar="hello"; I then open a new window on any path on the same domain - window.open("http://foo.com/any/path"); Then on the new window I find that…
odedbd
  • 2,285
  • 3
  • 25
  • 33
12
votes
1 answer

Access web storage from server side - possible?

I've stored some strings in web storage (session and/or local), and am wondering if it is possible to check for such stored strings on page load or init on the server-side (asp.net c# in my case)... So, for example, I will know not to re-fetch data…
brnwdrng
  • 521
  • 2
  • 8
  • 18
11
votes
1 answer

sessionStorage over localStorage in PhoneGap

I am currently developing a PhoneGap application and am using sessionStorage rather than localStorage because we are facing some problems with localStorage. Are there any downsides to using sessionStorage over localStorage?
Rohan Patil
  • 1,865
  • 1
  • 23
  • 36
9
votes
1 answer

Angular: Restore scope from sessionStorage

I am trying to retrieve my search and filter data from sessionStorage when the page refreshes. sessionStorage.restorestate returns undefined, does anyone know why? app.run(function($rootScope) { $rootScope.$on("$routeChangeStart",…
user1973285
8
votes
1 answer

sessionStorage on IE 11(Edge) got cleared when user navigate away

The behaviour of sessionStorage has been documented as it clears when the tab closes. However, in my practice, IE 11(Edge) in my client company clears sessionStorage when user navigates away within the tab (yes, the same tab is still open). With…
chfw
  • 4,502
  • 2
  • 29
  • 32
6
votes
2 answers

How to clear sessionStorage when navigating to another page but not on refresh?

I have some check boxes in one of my webpages, and this page has to refresh every 1 minute for some data consistency issues. I am using window.sessionStoage to persist the check boxes that have been checked so that the user doesn't lose the boxes…
Shubham Batra
  • 1,278
  • 1
  • 14
  • 27
6
votes
5 answers

Cast "null" as null in javascript

I use the session storage to set a key that can take numeric values or null. I noticed that the field is stored as a string no matter what I put in. Is there a nice way to convert back my stored value to null ? For instance, I want to do a check in…
QuantumLicht
  • 2,103
  • 3
  • 23
  • 32
5
votes
1 answer

sessionStorage in Firefox

in firefox 9, when i do: var msg = sessionStorage.getItem("message"); The browser ask with the error: "Operation is not supported", firefox not implement the webStorage of html5? or this case is only for sessionStorage and not for…
Kalamarico
  • 5,466
  • 22
  • 53
  • 70
4
votes
1 answer

LocalStorage, Looping through matched ID's, removing from the DOM

I have several localStorage Key's such as Cart, Viewed and Trash. The question is two fold: 1) How might I loop though the item ID's in localStorage in the most performant way, and if an ID already exists, add a class or data attribute to the…
ben corke
  • 43
  • 5
1
2 3
10 11