<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {
const x = document.getElementById("result");
if (typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 1;
}
x.innerHTML = "You have clicked the button " + localStorage.clickcount + " time(s)!";
} else {
x.innerHTML = "Sorry, no Web storage support!";
}
}
</script>
</head>
<body>
<h1>localStorage</h1>
<button onclick="clickCounter()" type="button">Click me!</button>
<p id="result"></p>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter will continue to count.</p>
</body>
</html>