what what - 1 year ago 73
Javascript Question

Store information using JavaScript

Please disregard this question.

I had zero idea what I needed to ask, which is why this question is phrased in a confusing manner, leading answerers astray. With the help of all the comments and answers, I now know what I need to look for.

Thank you all, and please vote to close this question.

On my webpage there is an image. When a user clicks on that image, the coordinates of their click are "observed" using JavaScript. I want to store the coordinates somehow, so I can later evaluate them. The coordinates are a string of six numbers separated by a comma that looks like this:

As I understand it, JavaScript cannot write to a file. So how and where can I save (or store) a string of characters using JavaScript, in a safe way?

The information is not sensitive and can be seen by anyone clever enough to read the JavaScript code. But it must be impossible for them to hack my server.

Answer Source

It looks like you want to save the info to a database on a server. In that case you would send the data through a POST http request (probably using ajax), receive it in a route on your server, save the info to a database, and then write backend code to use the information from the database however you see fit.

If you want to save the data just while the page is open, use a variable.

If you want to save it across sessions of the same page, but not forever, use localStorage or cookies.

If you want to save it for as long as you want, store the information in a database on a server.