Local storage:- JavaScript


  • It is a part of web storage.
  • The localStorage object will store the data with no expiration date.
  • When the browser is close the data will not be deleted, and will be available the next day, week, or year.
  • localStorage.setItem used to set the localstorage value.
  • localStorage.getItem used to get the localstorage value.
  • localStorage.removeItem used to remove the localstorage value.
Code:-

  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4. <head> 
  5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6. </head> 
  7.  
  8. <body> 
  9.  
  10.  <h1>Local Storage set & get</h1> 
  11.  
  12.  <input type="text" id="txt1"> 
  13.  <button onclick="set();">Set LocalStorage Value</button> 
  14.  
  15.  <br><br> 
  16.  <button onclick="get()">Get LocalStorage Value</button> 
  17.  
  18.  <br><br> 
  19.  <button onclick="del()">Remove LocalStorage Value</button> 
  20.  
  21.  <script> 
  22.   function set() 
  23.   { 
  24.    var t1 = document.getElementById('txt1').value; 
  25.    localStorage.setItem('key1', t1); 
  26.   } 
  27.  
  28.   function get() 
  29.   { 
  30.    var lv = localStorage.getItem('key1'); 
  31.    alert(lv); 
  32.   } 
  33.  
  34.   function del() 
  35.   { 
  36.    var lv = localStorage.removeItem('key1'); 
  37.    alert(lv); 
  38.   } 
  39.  </script> 
  40.  
  41. </body> 
  42.  
  43. </html>
Local storage:- JavaScript Local storage:- JavaScript Reviewed by Network security on November 13, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.