Tim Bordasch
Tim Bordasch

Reputation: 29

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

Upvotes: 1

Views: 187

Answers (2)

Yes you can use Window.localStorage, Syntaxis

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

Upvotes: 1

Alejandro Gonzalez
Alejandro Gonzalez

Reputation: 1371

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

Upvotes: 1

Related Questions