Is there a way to create a counter using JavaScript or Ajax that preserves its count even when the page is refreshed?
<script type="text/javascript">
var totalCount = parseInt(localStorage.getItem('counter')) || 0;
document.getElementById("p2").innerHTML = totalCount;
function countClicks() {
totalCount++;
localStorage.setItem('counter', totalCount);
document.getElementById("p2").innerHTML = totalCount;
}
</script>
</head>
<body>
<p>
<a href="javascript:countClicks();">Count Clicks</a>
</p>
<p id="p2">0</p>