I have a great JavaScript counter that maintains the count number even when the page is reloaded but not on another browser. I visit my website on another browser or another device the counter is reset. I'm using localStorage which I though was correct but I also tried globalStorage and that didn't work.
What am I missing?
JavaScript:
<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 + " <br>Subscribers So Far! And...<br>" + (1500 - +localStorage.clickcount) + "<br>Subscribers To Go" ;
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
</script>
HTML:
<p><button onclick="clickCounter()" id="paypal-btn1" type="button">Click me!</button></p>
<p><button onclick="clickCounter()" id="paypal-btn2" type="button">Click me!</button></p>
<p><button onclick="clickCounter()" id="paypal-btn3" type="button">Click me!</button></p>
<div id="result"></div>