如何删除网络储存?
在本地机器上储存敏感数据很危险,可能会留下安全漏洞。会话储存数据会在会话终止后立即被浏览器删除。
要清除本地储存设置,你需要调用 localStorage.remove(‘key’),其中‘key’是你要删除的值的键。如果你要清除所有设置,则需调用 localStorage.clear() 方法。
<!DOCTYPE HTML> <html> <body> <script> localStorage.clear(); // Reset number of hits. if( localStorage.hits ){ localStorage.hits = Number(localStorage.hits) +1; } else{ localStorage.hits = 1; } document.write("Total 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>
广告