I am using the clickCounter function below:
<script>
function clickCounter() {
if(typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = localStorage.clickcount ;
} else {
document.getElementById("result").innerHTML = "";
}
}
</script>
I can get onclick=clickCounter to work in a button, which shows the counter values in the code below. However, when the page loads, I can't get the clickCounter() function to fire so that the counter value is shown.
In other words, at page load I need to fire a call to the function so that id="result" has the count values in it.
<script>
document.getElementById("result").innerHTML = localStorage.clickcount ;
</script>
<font face="arial" size="3" color="black"><div>
<span id="result"></span> Downloads
</div></font>