Answer the question
In order to leave comments, you need to log in
How to organize the storage of a variable on the client side of the page?
Is it possible using javascript to store a variable on the client side that will increase when any user clicks on the button? That is, the first person entered and pressed send, the variable became equal to one, another person entered and sent - it became 2, etc. etc.
Answer the question
In order to leave comments, you need to log in
Store the counter on another server. For example, there is a Firebase service ( firebase.com ) that provides 100 MB of free space in the database, 5 GB of traffic and a maximum of 50 simultaneous connections. If this suits you, then this is the simplest option, where the code will be reduced to
var i = 0;
var fb = new Firebase("https://YOUR.firebaseio.com/");
fb.on("value", function(data) { // чтение
i = data.val().counter;
});
fb.set({ counter: i+1 }); // запись
If it is stored on the client side, then each client will have its own variable. Will have to store on the server.
If you are given such a task, then for the implementation you need to work with the server side. If there are no necessary accesses, you simply notify that it is impossible to do this for technical reasons, and this is no longer your problem.
But if you really need to do something, then perhaps on another server to work with this counter. Because the client side is individual and knows almost nothing about the outside world. The server part provides the general data. And nothing else.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question