如何刪除 Web 儲存?


在本地計算機上儲存敏感資料可能是危險的,可能會留下安全漏洞。在會話終止後,會話儲存資料將立即被瀏覽器刪除。

要清除本地儲存設定,你需要呼叫 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>

更新於: 28-1 月-2020

256 次瀏覽

開啟您的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.