HTML5 localstorage Implementation remember the password

Source: Internet
Author: User
Tags delete key sessionstorage

HTML5 provides two new ways to store data on the client:

    • Localstorage-Data storage with no time limit
    • Sessionstorage-Data storage for a session

the data stored by the Localstorage method has no time limit . Data is still available after the second, second, or next year.

The difference between Web storage and cookies

The concept of WEB storage is similar to a cookie, except that it is designed for larger capacity storage. The size of the cookie is limited, and every time you request a new page, the cookie is sent past, which virtually wastes bandwidth, and the cookie needs to specify the scope and cannot be called across domains.
In addition, WEB storage has methods such as setitem,getitem,removeitem,clear, unlike cookies that require front-end developers to encapsulate Setcookie,getcookie themselves.
However, cookies are also not available or missing: The role of cookies is to interact with the server as part of the HTTP specification, and the Web storage only for local "storage" of data

First, to determine whether the browser supports localstorage can use the following code:
if (window.localstorage) {alert ("Browse support Localstorage")}else{  alert ("Browse temporarily does not support Localstorage")}//or if (typeof Window.localstorage = = ' undefined ') {alert ("Browse temporarily does not support Localstorage")}

  

Second, the Code demo
<! DOCTYPE html>localstorage.setitem (' Keypass ', strpass);Alert ("Remember Password"); }else{localstorage.removeitem (' Keypass ');Alert ("Remember Password");        } window.location.reload (); }</script>Three. Basic usage of Localstorage:
SetItem Store value uses: Store value in key field usage:. SetItem (key, value) code example: Localstorage.setitem ("Site", "js8.in"  = Localstorage.getitem ("site"); RemoveItem Delete key purpose: Delete the value of the specified key local store usage:. RemoveItem (Key) code example: Localstorage.removeitem ("Site"); clear clears all key/value uses: Clears all key/value usages:. Clear ( ) Code example: Localstorage.clear ();

Original address:

Ultra-Simple Localstorage realizes the function of remembering the password

Other information:

HTML5 storage Methods Sessionstorage and Localstorage detailed

JavaScript remembers user name and login password (two ways) cookie

HTML5 localstorage Implementation remember the password

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.