"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > HTML web storage and web storage objects

HTML web storage and web storage objects

Published on 2024-07-29
Browse:836

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..
}

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");
Release Statement This article is reproduced at: https://dev.to/wasifali/html-web-storage-and-web-storage-objects-hcd?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3