'Website -> Count Button Clicks and never reset

Holaaa

I wanted to create a simple website containing a button. If I press the button 5 times, it says 5. When I refresh the page, it should still say 5. And when You load the page, it also says 5 and you can go on clicking.

I know how to build a counter for ONE session and one user, but I have nooo idea how to implement it to be stored "online".

I know that I need to implement a database to store the value and load the latest click-value once the website is opened but I dont know where to simply start



Solution 1:[1]

You can use localstorage to persist the count.

Example when the page starts:

var cat = localStorage.getItem('miGato');

Example to save the count:

localStorage.setItem('miGato', 'Juan');

The documentation is:

Localstorage

Solution 2:[2]

Yes you can use Window.localStorage, Syntaxis

var cat = localStorage.setItem('miGato', 'Juan');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy
Solution 2 Satyanarayan Bhuniya