0

I'm making a NeoCities site using HTML/CSS/Javascript. PHP doesn't seem to be supported without add-ons, so for the time being, i'm not considering that.

I want to see if I can have a button that simply says how many times it has been clicked, not just by the current user but by any user. I know that if I wanted it to show how many times a user clicked it, I could use localstorage or sessionstorage, but that does not seem to accomplish what I want to do. How can I store a variable that can be changed with an event that persists across users and sessions?

1
  • 3
    You need a server/backend/database that stores the value. You've mentioned and tagged JavaScript. Is it only frontend JavaScript or also backend JavaScript? Your goal is impossible using only frontend technologies. Commented Jun 9 at 23:21

1 Answer 1

1

I believe you need a backend language that runs on the server because using only Javascript on the client side every time a user send request to the page he will get the same exact Javascript code without a variable being modified.

Keep in mind that you don’t necessarily need a database, once you have a backend language you can keep track of the variable value in a text file on the server.

Possible solution

One possible solution you can make if you can't use PHP or any other backend language is to use a third-party service to keep track of that variable. In this case, every time the client Javascript will talk to the service (send a request to other server that can serve you as a database or file storage) and that server gives you the latest value.

You can use:

Google Sheets API – store and retrieve data using JavaScript by treating a sheet like a database
Firebase Realtime Database – a simple cloud database that works great with client-side JavaScript
JSONBin or MockAPI – free online REST APIs to store and fetch JSON data
GitHub Gist API – use gists to store data in a file-like way (not ideal for high traffic, but works for small-scale projects)
Formspree or Getform – services that allow writing data via POST requests even without backend code

Sign up to request clarification or add additional context in comments.

1 Comment

API stands for application programming interface. That's probably not what you actually mean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.