Reputation: 3907
I am trying to implement a counter that shows how many times a button is pressed. I can do this for a local user using cookies, but I would like to make it a counter of all users who have ever pressed the button, I am just not sure of the best way to go about this.
var counter = getCookie("buttonCount") || 0;
counter++;
document.cookie = 'buttonCount=' + counter + ";max-age" + (90) + ";";
document.getElementById("pressedCount").innerHTML = "Button pressed " + counter + " times";
Would it be possible to read in an integer from a file in the same directory as the html file, increment the value and write it back to the file?
Upvotes: 0
Views: 148
Reputation: 7279
This cannot be accomplished on just the client-side. What server-side language, if any, are you using?
Upvotes: 0
Reputation: 121
Create a simple server side script - using PHP or any other language that suits - that will store any user click and save it to file or database. Then on page load use another script to extract information about click count and display it for the user.
Upvotes: 1