localStorage cookie CRUD

 

1.localStorage (IE8 support more than 5m size)

Note: localStorage store to note that the type of conversion string type storage

    (When stored with the JSON.stringify () turn json string, JSON.parse () reducing the time taken)

    (When an object type data, if not processed directly into the localStorage, localStorage automatically convert data types, the object will be converted into [object Object])

增
window.localStorage.setItem(key,value)
删
window.localStorage.clear();清除所有
window.localStorage.removeItem(key);(删除key所对应的一条)
改
window.localStorage[key]=value
window.localStorage.key = value
查
let value = window.localStorage.getItem(key);
let value = window.localStorage[key];
let value = window.localStorage.key;

  

localStorage limitations

1, the size of the browser is not uniform, and it supports localStorage this property in more than IE8 IE versions

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 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

Here we analyze localStorage

2.cookie (4K size no compatibility problems)

note:

In the name or value of the cookie  in  you can not use a semicolon (;), comma (,), equal sign (=) and a space that is cookie assignment rules
By 
the session level (close browser gone) 
the document.cookie = 'name = value' 
specified period 
the document.cookie = "name = value; Expires =" + "date"; 
path specified 
the document.cookie = "name = value; = path /; Expires = "+ " date "; 
delete 
the document.cookie =" name = value; Expires = "+ " negative date "; 
modified 
repeat setting change is 
checked 
var STR = the document.cookie;

3.sessionStorage same as localStorage

 

Guess you like

Origin www.cnblogs.com/gitwusong/p/11413945.html