0% found this document useful (0 votes)
88 views1 page

Web Storage API

Uploaded by

GNINASSE Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views1 page

Web Storage API

Uploaded by

GNINASSE Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

 Tutorials  References  Exercises  Videos Pro NEW Website NEW Get Certified Log in

Dark mode
Dark code
 HTML CSS JAVASCRIPT SQL PYTHON PHP BOOTSTRAP HOW TO [Link] JAVA JQUERY C C++   
DOM Collections
DOM Node Lists ADVERTISEMENT

JS Browser BOM
JS Window
JS Screen
JS Location
JS History
Web Storage API
JS Navigator
❮ Previous Next ❯
JS Popup Alert
JS Timing
JS Cookies The Web Storage API is a simple syntax for storing and retrieving data in the browser. It is very easy to use:

JS Web APIs
Web API Intro Example
Web Forms API
Web History API [Link]("name", "John Doe");
Web Storage API [Link]("name");
Web Worker API
Web Fetch API Try it Yourself »
Web Geolocation API

JS AJAX The Web Storage API is supported in all browsers:

Chrome IE/Edge Firefox Safari Opera

Yes Yes Yes Yes Yes NEW

We just launched
W3Schools videos
The localStorage Object
The localStorage object provides access to a local storage for a particular Web Site. It allows you to store, read, add,
modify, and delete data items for that domain.

The data is stored with no expiration date, and will not be deleted when the browser is closed.

Explore now
The data will be available for days, weeks, and years.

The setItem() Method COLOR PICKER

The [Link]() method stores a data item in a storage.

It takes a name and a value as parameters:


Example

[Link]("name", "John Doe"); Get certified


by completing
a JavaScript
course today!

The getItem() Method school


w3 s

The [Link]() method retrieves a data item from the storage.


2

It takes a name as parameter:


CE

02

TI 2
R

FI .
ED

Example Get started

[Link]("name");

CODE GAME

ADVERTISEMENT

The sessionStorage Object


The sessionStorage object is identical to the localStorage object.
Play Game
The difference is that the sessionStorage object stores data for one session.

The data is deleted when the browser is closed.


ADVERTISEMENT

Example

[Link]("name");

Try it Yourself »

The setItem() Method


The [Link]() method stores a data item in a storage.

It takes a name and a value as parameters:

Example

[Link]("name", "John Doe");

The getItem() Method


The [Link]() method retrieves a data item from the storage.

It takes a name as parameter:

Example

[Link]("name");

Storage Object Properties and Methods


Property/Method Description

key(n) Returns the name of the nth key in the storage

length Returns the number of data items stored in the Storage object

getItem(keyname) Returns the value of the specified key name

setItem(keyname, value) Adds that key to the storage, or update that key's value if it already exists

removeItem(keyname) Removes that key from the storage

clear() Empty all key out of the storage

Related Pages for Web Storage API


Property Description

[Link] Allows to save key/value pairs in a web browser. Stores the data with no expiration
date

[Link] Allows to save key/value pairs in a web browser. Stores the data for one session

❮ Previous Next ❯

ADVERTISEMENT

ADVERTISEMENT

Report Error Forum About Buy Certificate

Top Tutorials Top References Top Examples Web Courses


HTML Tutorial HTML Reference HTML Examples HTML Course
CSS Tutorial CSS Reference CSS Examples CSS Course
JavaScript Tutorial JavaScript Reference JavaScript Examples JavaScript Course
How To Tutorial SQL Reference How To Examples Front End Course
SQL Tutorial Python Reference SQL Examples SQL Course
Python Tutorial [Link] Reference Python Examples Python Course
[Link] Tutorial Bootstrap Reference [Link] Examples PHP Course
Bootstrap Tutorial PHP Reference Bootstrap Examples jQuery Course
PHP Tutorial HTML Colors PHP Examples Java Course
Java Tutorial Java Reference Java Examples C++ Course
C++ Tutorial Angular Reference XML Examples C# Course
jQuery Tutorial jQuery Reference jQuery Examples XML Course

Get Certified »

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid
errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2022 by Refsnes Data. All Rights Reserved.


W3Schools is Powered by [Link].

You might also like