What I wanted to achieve was to have a random message displayed on the Web page after user clicks a button. I have a list of messages saved in a simple text file, each message on its own line.
Asked
Active
Viewed 101 times
-7
-
2You can't access the user's file system in any useful way in a browser. If you need to do this in the browser, you would have to have the user upload the file. In any case, it's not clear what you want. – Michael Mior May 29 '17 at 19:02
-
2Possible duplicate of [Javascript - read local text file](https://stackoverflow.com/questions/14446447/javascript-read-local-text-file) – Alator May 29 '17 at 19:02
-
Is the file on the user pc or the server? In the latter case, just use XHR, in the former use an input element with a FileReader. – Bergi May 29 '17 at 19:03
1 Answers
2
If you are on Node.js this will work using the Filesystem API
. If you are on a local web page the browser won't allow you to do this of safety reasons.
Here is an example of the Filesystem API
var fs = require("fs");
fs.writeFile("path/to/file", "Text", function(error){
});

Per Henrik Jakobsson
- 153
- 8