\
Html5 Web Storage includes two Storage methods: sessionStorage and localStorage.
SessionStorage is used to store data in a session locally, which can only be accessed by pages in the same session and is destroyed when the session ends. Therefore, sessionStorage is not a persistent local storage, only session level storage. Only access to the same window is allowed. \
And localStorage for persistent localStorage, unless actively delete data, otherwise the data is never expired. Cognate can read and modify localStorage data.
<! DOCTYPEhtml>
<html lang="en">
<head>
</head>
<body>
<script>
/ / setItem stored value
localStorage.setItem("name"."Xu Tongbao");
localStorage.setItem("job"."The web front end");
/ / the getItem method to obtain the value
var name = localStorage.getItem('name');
var job = localStorage.getItem('job');
console.log('Name:' + name);
console.log('Occupation:' + job);
/ / removeItem delete key
localStorage.removeItem('name');
var name = localStorage.getItem('name');
var job = localStorage.getItem('job');
console.log('Name:' + name);
console.log('Occupation:' + job);
//clear Clears all keys/values
localStorage.clear();
localStorage.removeItem('name');
var name = localStorage.getItem('name');
var job = localStorage.getItem('job');
console.log('Name:' + name);
console.log('Occupation:' + job);
</script>
</body>
</html>
Copy the code
\
Browser support:
\
\
Chrome View
\
\