HTMl5 of storage and localStorage difference and contact sessionStorage

localStorage and data storage properties allow sessionStorage key / value pairs in the browser.

LocalStorage data for long-term preservation of data for the entire site, saved time has not expired, until manually to delete.

localStorage attribute is read-only.

If you want to save the data in the current session, you can use sessionStorage property, temporarily change the data objects stored in the same window (or tab) data, these data will be deleted after closing the window or tab.

 

Save data syntax:

localStorage.setItem("key", "value");

Read data syntax:

var lastname = localStorage.getItem("key");

Delete data syntax:

localStorage.removeItem("key");

localStorage advantage

  •  1, localStorage expand the 4K limit the cookie.
  •  2, localStorage will be the first time the requested data is stored directly to a local, this is equivalent to a size of only 5M high version of the browser for the front page of the database, compared to the cookie can save bandwidth, but this is in only in support.

localStorage limitations

  •  1, the size of the browser is not uniform, and it supports localStorage this property in more than IE8 IE version.
  •  2, all current browsers will put localStorage value type is defined as a string type, this conversion takes some of us everyday more common JSON object type.
  •  3, localStorage in the browser's privacy mode following is unreadable.
  •  4, the localStorage is essentially a reading of the string, if the stored content and more words will consume memory space will cause the page to change the card.
  •  5, localStorage crawler can not be crawled.

The only difference is that localStorage localStorage and sessionStorage belong to permanent storage, and sessionStorage belong when the session ended, sessionStorage key-value pairs will be cleared.

 

Outer, localStorage only supports string type of memory, no matter what type of value stored, read out the type String.

 

 Here what reads at his hospital, but officials recommend the use of a third.

 

Precautions:

Generally, we will JSON stored in localStorage, but localStorage localStorage will automatically be converted into a string.

This time we can use JSON.stringify () This method, to be converted into JSON JSON string.

Guess you like

Origin www.cnblogs.com/art-poet/p/12022043.html