JavaScript window.sessionStorage Property

You are Here:

JavaScript window.sessionStorage Property

The window.sessionStorage property allows you to access and save data (key/value pairs) in a web browser.

Note: The key points for window.sessionStorage property as follows

  • Unlike localStorage, the data stored in sessionStorage is cleared when the page session ends.
  • Closing a tab/window ends the session and clears objects in sessionStorage.
  • The keys and values are always strings.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var len = window.sessionStorage.length; var txt = "The session storage length is " +len; document.write(txt); </script> </body> </html>

Syntax

window.sessionStorage

Save and Access Session Storage

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); // adding one data to session storage if(typeof(Storage) !== "undefined"){ sessionStorage.name = "Cooper"; x.innerHTML = sessionStorage.name; } else { x.innerHTML = "Sorry, your browser does not support web storage."; } // check session storage length var len = window.sessionStorage.length; var txt = "The session storage length is " +len; document.write(txt); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author