0

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>
halfer
  • 19,824
  • 17
  • 99
  • 186
T.Doe
  • 1,969
  • 8
  • 27
  • 46
  • You can't do this in pure javascript. Javascript is client-side, and unique for each browser being used. You'll need to have something identifying the user, such as some sort of login or similar - or preferably a login + server-side code. – junkfoodjunkie Nov 02 '16 at 01:46
  • Oh wow I didn't know that but it certainly makes a lot of sense. Thank you @junkfoodjunkie – T.Doe Nov 02 '16 at 01:47
  • https://en.wikipedia.org/wiki/Web_storage - localStorage is for data stored in the user's web browser. Obviously that won't be magically available to other people's web browsers. – Lightness Races in Orbit Jan 31 '17 at 20:27

1 Answers1

0

local storage will not another browsers instead of that you can use sessions or cookies reffer

Community
  • 1
  • 1