<html> <body> <script> if (location.href.indexOf("clear=true") != -1) { localStorage.removeItem("foo"); alert("CLEAR"); } else { var initialValue = localStorage.getItem("foo") || "EMPTY"; localStorage.setItem("foo", "bar"); alert(initialValue); } </script> </body> </html>