HTML5 Web Storage


HTML 5 API is providing an amazing feature to handling data locally instead of cookies.
In this article, we are going to look into the HTML 5 Web Storage. Before HTML 5 web storage, we are storing data using Cookies.


After reading this article you will get a deep understanding of local storage

HTML5 has provided an API called web storage, the web storge provides two objects to store the data in a web browser.
  1. Local storage
  2. Session storage
Before we are going to use the web storage, need to ensure the browser is having a capability or not,

Using the syntax we can able to find out this. typeof(Storage) !== "undefined".

All the modern browsers are supporting this feature

localStorage Object

Using localStorage we can store the data in the browser without expiration. The data will be available always(day, month, year).

The localStorage data will be available in all the tabs of the browser

Methods in localStorage

  1. setItem - is used to store the data in browser
  2. getItem - retrieve the data from localStorage
  3. removeItem - remove the data from localStorage
localStorage.setItem("name","WebStorage");
localStorage.getItem("name")
"WebStorage"
localStorage.removeItem("name");

sessionStorage Object

Session Storage is almost equal to the local storage, but the session storage data will be erased when the user closes the particular tab.








Comments