Removing localStorage entries - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window localStorage

Description

Removing localStorage entries

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w  w  w .  j a v  a 2  s .  com*/
var foo = localStorage.getItem('foo');
if (foo) {
   console.log('i had it, now i remove it');
  localStorage.removeItem('foo');
} else {
   console.log('i didnt have it, now i set it');
  localStorage.setItem('foo', 'bar');
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials