H5 local storage

The localStorage and sessionStorage attributes allow key/value pair data to be stored in the browser.
localStorage is used to save the data of the entire website for a long time. The saved data has no expiration time until it is manually deleted.
sessionStorage is used to temporarily save the data of the same window or tab, which will be deleted after the window or tab is closed


localStorage: local storage
It is used to save the data of the entire website for a long time. The saved data has no expiration time until it is manually deleted. The attribute is read-only. localStorage only supports string type storage. It should be noted here that the use of localStorage also follows the same-origin policy, so different websites cannot directly share the same localStorage.

Syntax:
window.localStorage
Save data
localStorage.setItem(‘key’,’value’)
Read data
var lastname = localStorage.getItem(‘key’)
Delete data
localStorage.removeItem(‘key’)
sessionStorage local storage
sessionStorage is used to temporarily save the data of the same window (or tab), which will be deleted after the window or tab is closed
Tip: If you want to keep the data after the browser window is closed, you can use the localStorage property. The data object has no expiration time, unless you delete it manually
Syntax: window.sessionStorage
Save data
sessionStorage.setItem(‘key’,’value)

Read data:
sessionStorage.getitem(‘key’)
Delete specified Key data

sessionStorage.removeItem(‘key’)
Remove all data
sessionStorage.clear ()

The localStorage and sessionStorage attributes allow key/value pair data to be stored in the browser.
localStorage is used to save the data of the entire website for a long time. The saved data has no expiration time until it is manually deleted.
sessionStorage is used to temporarily save the data of the same window or tab, which will be deleted after the window or tab is closed


localStorage: local storage
It is used to save the data of the entire website for a long time. The saved data has no expiration time until it is manually deleted. The attribute is read-only. localStorage only supports string type storage. It should be noted here that the use of localStorage also follows the same-origin policy, so different websites cannot directly share the same localStorage.

The localStorage and sessionStorage attributes allow key/value pair data to be stored in the browser.

localStorage is used to save the data of the entire website for a long time. The saved data has no expiration time until it is manually deleted.

sessionStorage is used to temporarily save the data of the same window or tab, which will be deleted after the window or tab is closed

localStorage: local storage

It is used to save the data of the entire website for a long time. The saved data has no expiration time until it is manually deleted. The attribute is read-only. localStorage only supports string type storage. It should be noted here that the use of localStorage also follows the same-origin policy, so different websites cannot directly share the same localStorage.

Syntax:

window.localStorage

Save data< /strong>

localStorage.setItem(‘key’,’value’)

Read data

var lastname = localStorage.getItem(‘key’)

Remove data

localStorage.removeItem (‘key’)

sessionStorage local storage

sessionStorage is used to temporarily save the data of the same window (or tab), which will be deleted after the window or tab is closed

Prompt : If you want to keep the data after the browser window is closed, you can use the localStorage property. The data object has no expiration time, unless you delete it manually

Syntax: window.sessionStorage< /strong>

Save data

sessionStorage.setItem(‘key’,’value)

Read data:

sessionStorage.getitem(‘key’)

Delete the data of the specified key< /strong>

sessionStorage.removeItem(‘key’)

Remove all data

< strong>sessionStorage.clear()

Leave a Comment

Your email address will not be published.