DEV Community

wasifali
wasifali

Posted on

3

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..
}
Enter fullscreen mode Exit fullscreen mode

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");
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay