About H5 Headquarters Cache Localstorage,sessionstorage

Source: Internet
Author: User
Tags 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

Previously, these were all done by cookies. However, cookies are not suitable for storing large amounts of data because they are passed by each request to the server, which makes the cookie slow and inefficient.

How to use:

Localstorage.setitem ("Menutitle", Arrdisplay);
Sessionstorage.getitem (' Key_null ')
Sessionstorage.removeitem (' page ')

In the process of doing the project encountered a rare Safari browser H5 Local storage does not support the situation, just beginning to think is the phone model and iOS version of the relationship, after a comparison to find that the mobile phone opened no trace of the cause of browsing, check the summary as follows:

The specific performance of the mobile Safari browser is:

    • Localstorage Object still exists
    • But SetItem will report an exception: Quotaexceedederror
    • GetItem and RemoveItem directly ignored

Console in Safari

Determine if the browser is non-marking

if(typeofLocalstorage = = = ' object ') {    Try{Localstorage.setitem (' Localstorage ', 1); Localstorage.removeitem (' Localstorage '); return true; } Catch(e) {//storage.prototype._setitem=Storage.prototype.setItem; Storage.prototype.setItem=function() {}; Alert (' Local storage not supported '); return false; }}

About H5 Headquarters Cache Localstorage,sessionstorage

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.