当前位置:网站首页>Localstorage and sessionstorage

Localstorage and sessionstorage

2022-07-07 16:45:00 Supreme and peerless

WebStorage It mainly provides a mechanism , You can let the browser provide a better way than cookie More intuitive key、value storage :

localStorage: The local store , What is provided is a kind of Permanent storage method , stay Close the web page and reopen when , Stored content will remain ;

seesionStorage: Session storage , What is offered is Storage of this session , When closing a session , The stored content will be cleared ;

localStorage and sessionStorage The difference between

So what's the difference between them ?
Verification one : Close the page and reopen ,localStorage Will retain , and sessionStorage Will be deleted ;
Verification II : Jump in the page ,localStorage Will retain ,sessionStorage And keep it ;
Verification III : Jump outside the page ( Open a new page ),localStorage Will retain ,sessionStorage Will not be retained ;
Storage Common methods and properties
attribute :
Storage.length: Read-only property
* Returns an integer , Indicates stored in Storage Number of data items in the object ;
Method :
Storage.key(index): This method accepts a value n As a parameter , Returns the... In storage n individual key name ;
Storage.getItem(): The method accepts one key As a parameter , And back to key Corresponding value;
Storage.setItem(): The method accepts one key and value, And will put key and value Add to storage .
* If key Storage , Then update its corresponding value ;
Storage.removeItem(): The method accepts one key As a parameter , And put the key Delete... From storage ;
Storage.clear(): The function of this method is to empty all the data in the storage key;
原网站

版权声明
本文为[Supreme and peerless]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071441078153.html