Storage Classes in HTML5

Storage Classes in HTML5 

 
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:
  1. localStorage.setItem('favoriteflavor','vanilla');  
If you read out the favoriteflavor key, you will get back "vanilla":
  1. var taste = localStorage.getItem('favoriteflavor');  
  2. // -> "vanilla"  
To remove the item, you can use- the removeItem() method:
  1. localStorage.removeItem('favoriteflavor');  
  2. var taste = localStorage.getItem('favoriteflavor');  
  3. // -> 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.

Foreantech
Foreantech - A complete online solution company.