Web Storage In HTML5

Web Storage In HTML5 

 
HTML5 provides us the property of web storage. It was also done by cookies but cookies are not the easy way to store a large amount of data, because they are passed every request to the server. Hence it was very slow to deal with cookies.
 
HTML provides us the facility in which the data is not passed by every server request, it is used only when we need this and it is easy to store a large amount of data. The data is stored in a different part of the website and each website can access its own data. HTML5 uses javascript to store the data.
 
There are two types of objects for storing data.
 
1. Local storage
2. Session Storage
 
Local Storage: It stores data which has no limit. The data will be available next day, week and year
  1. <!DOCTYPE html>  
  2. <html>  
  3.     <body>  
  4.         <script type="text/javascript">  
  5. localStorage.city="jaipur";  
  6. document.write("City: " + localStorage.city);  
  7. </script>  
  8.     </body>  
  9. </html>  
Session Storage: It stores data for one session. The data is deleted when the user closes the window.
  1. <!DOCTYPE html>  
  2. <html>  
  3.     <body>  
  4.         <script type="text/javascript">  
  5. sessionStorage.city="jaipur";  
  6. document.write(sessionStorage.city);  
  7. </script>  
  8.     </body>  
  9. </html>