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!





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...