HTML web storage and web storage objects

PHPz
Release: 2024-07-17 00:32:30
Original
673 people have browsed it

HTML web storage and web storage objects

HTML Web Storage

With web storage, web applications can store data locally within the user's browser.
Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance.
Web storage is per origin i..e per domain and protocol. All pages, from one origin, can store and access the same data.

API and Web Storage

Google= 4.0
Microsoft Edge= 8.0
Firefox= 3.5

HTML Web Storage Objects

HTML web storage provides two objects for storing data on the client:
window.localStorage - stores data with no expiration date
window.sessionStorage - stores data for one session

if (typeof(Storage) !== "undefined") {
  // Code for localStorage/sessionStorage.
} else {
  // Sorry! No Web Storage support..
}
Copy after login

The localStorage Object

The localStorage object stores the data with no expiration date.
The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

// Store
localStorage.setItem("lastname", "Smith");

// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
Copy after login

The above is the detailed content of HTML web storage and web storage objects. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!