HTML5 Web Storage (Web Storage) technology and usage

Source: Internet
Author: User
Tags sessionstorage

In today's web development, HTML5 is one of the biggest topics we've talked about. HTML5 offers new features that empower web programmers and eliminate the effort to delve into ways to make websites better, faster, and more flexible. One of these new features that really interests me is Web Storage (Web Storage). Web Storage (Web Storage) provides a way to save user session information on the browser side. Let's take a look at the basic usage of Web Storage (Web Storage)!

Basic Essentials of Web Storage (Web Storage)
    • The stored data can be structured data for any class JSON.
    • The stored data does not expire as the session expires when the user browses, but is deleted at the user's request. Browsers also remove them because of storage space limitations or security reasons.
    • The stored information can be used under the entire domain name.
Methods in Web Storage (Web Storage)
    • SetItem (Key,value): sessionStorage adds a key/value data to the object.
    • GetItem (Key): Gets the value based on key.
    • Clear (): Empties the sessionStorage object.
    • RemoveItem (key): sessionStorage deletes a data from the object.
    • Key (N): Gets the value of key[n].
Setting the Key/value value

There are two ways to put information sessionStorage in:

Sessionstorage.setitem (' Somekey ', ' somevalue ');

... You can also use a more concise approach:

Sessionstorage.somekey = ' somevalue ';
Gets a value:

There are also two ways to get a value:

// returns ' Somevalue '

... Or a simple reference sessionStorage :

// returns ' Somevalue '
Delete a Key/value
// returns ' undefined ' for Somekey

All you need to do is to provide the key value to the removeItem method.

Clear Data
// everything 's gone.

Simply call the clear () method, and nothing is needed.

A simple example of Web Storage (Web Storage) usage
<href= "javascript:;" OnClick = "If" (Sessionstorage && sessionstorage.getitem (' name ')) {alert (' Hurry back Oh, ' + sessionstorage.getitem (' name ') ); } "> logout </a>

When the user clicks the logout link, the page talks to the dialog box says "Hurry back Oh, xxx"!

Browser support for HTML5 Web Storage (web Storage)

The most critical feature of all cool features is the browser support, and fortunately, all modern browsers support HTML5 Web Storage (Web Storage), which is supported from the beginning of IE8. If you want to support IE6, IE7, then do it yourself.

HTML5 Web Storage (Web Storage) is very simple but also very useful. Because HTML5 Web Storage (web Storage) needs to operate with JavaScript, make sure that the browser supports this feature and turns on the Javascrpt scripting feature when using it to perform some key functions.

Do you think HTML5 Web Storage (Web Storage) is useful? Have they been used in your application?

Transfer from http://www.webhek.com/web-storage/

HTML5 Web Storage (Web Storage) technology and usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.