Posted about 3 years ago. Visible to the public. Repeats.

sessionStorage: Per-window browser storage

All major browsers (IE8+, FF3.5+, Safari 4+, any Chrome) support sessionStorage, a JavaScript storage object that

  • survives page reloads and browser restores,
  • but is different per new tab/window (in contrast to localStorage which is shared across all tabs).

MDN says:

The sessionStorage object is most useful for hanging on to temporary data that should be saved and restored if the browser is accidentally refreshed


Example usage:

// Save data to the current session's store sessionStorage.setItem("username", "John"); // Access some stored data alert( "username = " + sessionStorage.getItem("username"));

As a demo, check out this jsFiddle which will assign a random number


  • sessionStorage can only store string keys and values (like localStorage). If you need to store structured data you need to use JSON.stringify(object) and JSON.parse(string).
  • sessionStorage is unavailable (null) in private browsing mode on Safari and the default Android WebKit browser.
  • In Chrome, duplicating a tab (e.g. by middle-clicking the reload button) will cause the new tab to use the same sessionStorage.
  • In Chrome, tabs opened via will also use the same sessionStorage.

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Arne Hartherz
Last edit:
over 1 year ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more