I have the following html code to clear web storage data after click the button "Clear storage".
The explorer (chrome and firefox) just never trigger the function clear after click the button of clear storage.
The code is:
<html>
<head>
<script>
function clear() {
console.log();
localStorage.clear();
refreshContents();
alert("all cache data cleared!");
}
function refreshContents() {
var str = "";
alert("in refresh");
for (var i = 0, len = localStorage.length; i < len; i++) {
var k = localStorage.key(i);
var v = localStorage.getItem(k);
str += "'" + k + "' = '" + v + "'<br />";
}
alert("after for loop");
key.value = "";
value.value = "";
content.innerHTML = str;
}
</script>
</head>
<body>
<div class="content"> <!-- end .content -->
<p>This is the logout page.</p>
<p>All temporary data will be erased after logout.
<p> </p>
<input type="button" onclick="clear();" value="Clear Storage" />
Contents of Local Storage:<br />
<span id="content"></span>
</body>
</html>
Can someone help please. Thanks in advance!