- 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:-
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <h1>Local Storage set & get</h1>
- <input type="text" id="txt1">
- <button onclick="set();">Set LocalStorage Value</button>
- <br><br>
- <button onclick="get()">Get LocalStorage Value</button>
- <br><br>
- <button onclick="del()">Remove LocalStorage Value</button>
- <script>
- function set()
- {
- var t1 = document.getElementById('txt1').value;
- localStorage.setItem('key1', t1);
- }
- function get()
- {
- var lv = localStorage.getItem('key1');
- alert(lv);
- }
- function del()
- {
- var lv = localStorage.removeItem('key1');
- alert(lv);
- }
- </script>
- </body>
- </html>
Local storage:- JavaScript
Reviewed by Network security
on
November 13, 2019
Rating:
No comments: