如何刪除網路儲存?


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

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

更新於:2020 年 1 月 28 日

256 次瀏覽

開啟你的 職業生涯

透過完成這堂課獲得認證

開始
廣告
© . All rights reserved.