Features of Session Storage

  • SessionStorage is used to store the session information of the user.
  • A session is started when a user login or after visiting a web page.
  • This session is said to be ended when the user signs out or closes the tab.
  • Data persists if a page refreshes.
  • This session storage data is automatically cleared by the browser when a session is ended.
  • Data is stored in the form of key-value pairs.
  • Each tab has its own session Storage. Other tabs or windows, even the same website or origin cannot access this data.
  • Depending upon the browser, storage limit for a origin(domain + port + protocol) will be up to 5 MB on each tab.

Example: We visited a site A in Tab 1 , and the same site in Tab 2, each tab has it’s own session storage up to 5 Mb. Other web pages from the same origin can use this data in that session.

How to save data in session and local storage ?

SessionStorage and LocalStorage are the two most important ways to store data in the browser. SessionStorage is the temporary storage that web applications use to store data, whereas LocalStorage is the persistent storage that websites use to manage our data. These storages reside in the browser’s memory.

Apart from these storage browser also stores information in Cookies. A Cookie is just some textual information about website. Cookies help to make the browsing experience better. Cookies are website specific and hold the information of frequently visited websites

Table of Content

  • Steps to open Session Storage and Local Storage
  • Memory Capacity
  • Features of Session Storage
  • When to use Session Storage?
  • Methods of Session Storage object
  • Demonstrating Session Storage
  • Features of Local Storage
  • When to use LocalStorage?
  • Methods of Local Storage object
  • Demonstrating Local Storage Object

Similar Reads

Steps to open Session Storage and Local Storage:

...

Memory Capacity

Step 1: Go to the developer console (F12 in Chrome), Step 2:Then choose the Application tab. Step 3: In the Application Tab, we can see the Storage Menu. Step 4: In the Storage Menu, we can look at different types of storage and their data, as seen in the below picture....

Features of Session Storage :

Session Storage: 5 MB Local Storage: 10 MB...

When to use Session Storage?

SessionStorage is used to store the session information of the user. A session is started when a user login or after visiting a web page. This session is said to be ended when the user signs out or closes the tab. Data persists if a page refreshes. This session storage data is automatically cleared by the browser when a session is ended. Data is stored in the form of key-value pairs. Each tab has its own session Storage. Other tabs or windows, even the same website or origin cannot access this data. Depending upon the browser, storage limit for a origin(domain + port + protocol) will be up to 5 MB on each tab....

Methods of session storage object

We want to store data only for a session. We want to maintain sessions. When dealing with transactions and sensitive information. When we do not want other tabs or windows to access or share the information. When we want the data to be erased when the session ends....

Demonstrating Session Storage

sessionstorage.setItem(key,value); // Adds data in key-value pair sessionstorage.getItem(key); // Gets the data for the given key sessionStorage.removeItem(key); // Removes the (key, value) pair data for the given key sessionstorage.key(index); // Gets the key based on the index position sessionstorage.length; // Returns the length of the storage list. sessionstorage.clear(); // Clears all the session storage...

Features of LocalStorage:

Example: The following example demonstrates session storage...

When to use LocalStorage?

...

Methods of localstorage object

LocalStorage is used to store the information of the user persistently in the browser. It does not get cleared unless JavaScript code running on that website deletes it or we erase it using browser settings. Data stored in local storage is not sent for the server upon every request. Data is not lost even if we close the browser, or restart the computer. Data is stored in the form of key- value pairs. The web pages from the same origin in the other tabs/windows can also use this local storage data. Depending upon the browser, storage limit for a origin(domain + port + protocol) will be up to 10 MB....

Demonstrating LocalStorage Object

We want to store data persistently. When we do not want to lose data if the tab or browser is closed. Want to store user activity and track user actions. Need not maintain sessions. Other tabs or windows can access the stored data, which can be shared with other tabs or windows with the same origin....

Contact Us