Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use web local storage in html5

Shulou Source: shulou.com Published: 2022-06-03 07:17:37 09月18日 Update

This article mainly introduces how to use web local storage in html5, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.

Html5 provides us with a local caching mechanism that will replace our cookie, and it will not be sent to our server side with the browser. We can use js to operate the local cache freely on the client side. The main caches in html5 are localStorage, and sessionStorage. Their usage is the same. The difference is that they have different time limits. There is no time limit for localStorage. SessionStorage is now based on session data storage, after shutting down or leaving the site, the data will be deleted.

Let's take a brief look at the official example operation:

Javascript

The code is as follows:

LocalStorage.fresh = "vfresh.org"; / / set a key value

Var a = localStorage.fresh; / / get the key value

Or use its API:

Javascript

The code is as follows:

/ / clear storage

LocalStorage.clear ()

/ / set a key value

LocalStorage.setItem ("fresh", "vfresh.org")

/ / get a key value

LocalStorage.getItem ("fresh")

/ / return "vfresh.org" / / gets the name of the key of the specified subscript (like Array)

LocalStorage.key (0)

/ / return "fresh" / / Delete a key value

LocalStorage.removeItem ("fresh")

If sessionStorage is the same, there is no need to talk nonsense. It is the cookie of our expiration time Expire=0.

Thank you for reading this article carefully. I hope the article "how to use web Local Storage in html5" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles storage time cache code data restrictions different same consistent free subscript not used value interest at the same time name official customer client Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB Shulou Technology Shulou Tech Info Xiaomi