Thursday, August 31, 2017

Local storage in the browser


  • The read-only local-storage property allows you to access a Storage object for the Document's origin;
  • The stored data is saved across browser sessions. 
  • local-storage is similar to session-storage, except that while data stored in local-storage has no expiration time, data stored in session-storage gets cleared when the page session ends — that is, when the page is closed.



Edit in plnkr

We can see the local storage values in the browser as shown below


Add data to the storage object
 //Use local storage to store items
  var localStore=window.localStorage;
  localStore.setItem('userId','1');
  localStore.setItem('pwd','1234')

Remove data from the storage object
  console.log("***\n Remove data from the local storage object");
  localStore.removeItem('userId');
  localStore.removeItem('pwd')

No comments:

Post a Comment