0

I want a variable that would be the exact same for everyone. Reason I want this is because I want a download count that people can see. For every download, the download count goes up.

How would I do like this?

var downloadCount = "";
 function addDownloadCount() {
'use strict';
downloadCount = downloadCount + 1;
}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
Jeff
  • 11
  • 4
  • you can not do that, you store this count somewhere in your server then write to it to add one and read from it to get count – Scott Selby Jan 04 '16 at 06:14
  • If it is on a server, just use file IO. (Have a download counts file and just increment.) – intboolstring Jan 04 '16 at 06:14
  • This might help - http://stackoverflow.com/questions/5786851/define-global-variable-in-a-javascript-function – Liren Yeo Jan 04 '16 at 06:15
  • @Liren - no that won't help . OP wants a count that stays constant across all users requesting data not just to stay constant for one users session – Scott Selby Jan 04 '16 at 06:16
  • 1
    *in `HTML` and `Javascript`* and you tagged `C#`?! – Ghasem Jan 04 '16 at 06:16
  • Anyways you need to save the count in a database and increase it by every click on your download link. – Ghasem Jan 04 '16 at 06:17
  • @AlexJolig - no , that would be silly to pay for database storage to store a download count number , a text or xml file would work just fine – Scott Selby Jan 04 '16 at 06:18
  • 1
    @ScottSelby No, it would be *stupid* to do that in the javascript scope. Doing it in the database is an overkill at most. Lets start with a working solution, and only then make it better. – SimpleVar Jan 04 '16 at 06:18

1 Answers1

1

The client side storage locations such as local storage, script variables wont help you in this scenario, since it cannot be accessed from another other users. You cannot use such a Global variable for all users in clent side(either html or java script), you have to use server side storage like session or application variable

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88