
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Store a Name Permanently Using HTML5 Local Storage
The Local Storage is designed for storage that spans multiple windows and lasts beyond the current session. In particular, Web applications may wish to store megabytes of user data, such as entire user-authored documents or a user's mailbox, on the client side for performance reasons.
HTML5 localStorage saves string data in the browser and lasts beyond the current session. localStorage stores the data, with no expiration, whereas sessionStorage is limited to the session only. When the browser is closed, the session is lost.
The data won’t get deleted when the browser is closed. Here, we will save the name for example.
You can try to run the following code to learn how to store a name permanently using HTML5 local storage
Example
<!DOCTYPE html> <html> <body> <div id = "demo"></div> <script> if (typeof(Storage) !== "undefined") { localStorage.setItem("name", "John"); document.getElementById("demo").innerHTML = localStorage.getItem("name"); } else { document.getElementById("demo").innerHTML = "The browser do not support Web Storage"; } </script> </body> </html>
Advertisements