How to use Delete Web storage in HTML5

In this article, I will go to explain Delete Web storage in HTML5.
  • 2205

Delete Web Storage in HTML5

  • Storing sensitive data on local machine could be dangerous and could leave a security hole.

  • The Session Storage Data would be deleted by the browsers immediately after the session gets terminated.

  • In Local Storage, you want to clear setting, you would need to call localStorage.remove('key'); where 'key' is the key of the value you want to remove.

  • In Local Storage, you want to clear all settings, you need to call localStorage.clear() method.

Example

Following is the code which would clear complete local storage

<!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>

Output

delete storage.jpg

Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.