By | July 18, 2013
Storage in HTML was done with the help of cookies. The exciting thing about this storage is that it’s fast as well as secure.
Two types of storage are in HTML5

  1. Local Storage : In this object stores data for a larger period of time even if the browser is closed.
  2. Session Storage : In this object stores data for a specific session.

Methods :
Using local storage in modern browsers is ridiculously easy.
All you have to do is modify the localStorage object in JavaScript.
You can do that directly use the setItem() and getItem() method:


If you read out the favoriteflavor key, you will get back “vanilla”:

var taste = localStorage.getItem(‘favoriteflavor’);
                                              // -> “vanilla”

To remove the item, you can use- the removeItem() method:

          var taste = localStorage.getItem(‘favoriteflavor’);
                                                   // -> null

That’s it! You can also use sessionStorage instead of localStorage if you want the data to be maintained only until the browser window closes.

Leave a Reply

Your email address will not be published. Required fields are marked *