在HTML5中删除Web存储
- 将敏感数据存储在本地机器上可能是危险的,可以留下安全漏洞。
- 会话存储数据将在会话终止后立即删除浏览器。
- 在本地存储中,我们想要清除设置,我们需要调用localstorage.remove('键');其中"键"是我们要删除的值的键。
- 在本地存储中,我们希望清除所有设置,我们需要调用localstorage.clear()方法。
在HTML5中删除Web存储示例
<!DOCTYPE HTML> <html> <body> <script type="text/javascript"> localStorage.clear(); if (localStorage.hits) { localStorage.hits = Number(localStorage.hits) + 1; } else { localStorage.hits = 1; } document.write("Total Number of Hits :" + localStorage.hits); </script> <p>Refreshing the page would not to increase hit counter.</p> <p>Close the window and open it again and check the result.</p> </body> </html>
日期:2020-04-11 23:04:08 来源:oir作者:oir