<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The localStorage Property</h2>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<p>Number of clicks: <span id="demo"></span></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 (is not reset).</p>
<script>
document.getElementById("demo").innerHTML = localStorage.clickcount;
function clickCounter() {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("demo").innerHTML = localStorage.clickcount;
}
</script>
</body>
</html>