October 1, 2016

JavaScript localstorage with good example



In javascript using localstorage you can simply save any single OR array value same like work as a PHP session.


There is a simple solution though, and that’s to use local storage.

The good news is to stored any data to computer so when page reload then you can get data back from localstorage.


WHAT IS EXACT MEANING OF LOCAL STORAGE?

  • Local Storage: stores data with no expiration date and this is the one we will be using because we want our to-do’s to stay on the page for as long as possible.
  • Session Storage: only saves the data for one session so if the user closes the tab and reopens it all their data will be gone.

BELOW ARE SOME EXAMPLE FOR SET VALUE, GET VALUE AND CLEAR VALUE FROM LOCAL STORAGE

To set item into local storage:

localStorage.setItem('username', 'admin');

To get value from local storage:
localStorage.getItem('username');
Output: admin

To clear any value from local storage:
localStorage.removeItem('username');


Enjoy!





1 comment:

  1. Thanks for the sharing this blog is very intersting. It's very informarmative and very knowladgeable blog.
    We at Genesis have the best expertise to provide web designing services, software testing,Internet marketing services, web designing services,
    data scraping and many more.

    ReplyDelete

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...