Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use localStorage in HTML5

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use localStorage in HTML5". In daily operation, I believe many people have doubts about how to use localStorage in HTML5. Xiaobian consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to use localStorage in HTML5"! Next, please follow the small series to learn together!

Html5 local storage is data stored locally by the browser.

The basic usage method is as follows:

JavaScript Code Copy content to clipboard

localStorage.firstName = "Tom";

alert(localStorage.firstName);

In this case, the data is saved locally, but in what form is the local data saved? After tracking, it is found that in Chrome browser, the data is stored in the form of sqlite database files.

Under windows, it is saved under C:/Documents and Settings/User Name/Local Settings/Application Data/Google/Chrome/User Data/Default/Local Storage path (where User Name refers to the current user name);

On Mac, it is saved under the path/Users/User Name/Library/Application Support/Google/Chrome/Default/Local Storage (where User Name is the current user name)

Although the suffix name is. localstore, it is actually a sqlite database file, which can be opened with sqlite and the data in it can be seen. (can be opened using firefox SQLite Manager add-on)

The installation steps are similar to installing firebug. Select Menu Tools--> Accessories, open the Accessories Settings page, search for "SQLite Manager" keyword, install the "SQLite Manager" plug-in and restart firefox. You can see the "SQLite Manager" add-on in the tool:

Here are a few common localStorage methods:

1. Add localStorage

XML/HTML Code Copy content to clipboard

localStorage.setItem("key","value"); //stores a value "value" with the name "key"

2. Get localStorage

XML/HTML Code Copy content to clipboard

localStorage.getItem("key"); //Get a value named "key"

Delete localStorage

XML/HTML Code Copy content to clipboard

localStorage.removeItem("key"); //Delete information named "key"

4, Empty localStorage

XML/HTML Code Copy content to clipboard

localStorage.clear(); //clear localStorage

5. View localStorage that has been saved

Available in Chrome console tool Resource-Local Storage

At this point, the study of "how to use localStorage in HTML5" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report