1

I want to create / write to file using javascript from local file. I can read local files using

$.get('file.txt', function (data) {
    //my code
}, 'text'); 

Is there similar way to write to files? It is and will all be done locally, from file to file. Also I can not really use local storage for my purposes.

Edit: I do not want to output blob. And for what I am trying to create - I have this lets call it puzzle that user tries to solve. And I want to log time when he started and when he ended. I do not want them to see their files, becouse they could edit them, same as local storage can be edited or cleaned. I want to create and edit local file without users knowledge. It will all be done locally on my computer.

somik07
  • 39
  • 9
  • you must use node, there is no option to write from front-js – Álvaro Touzón Sep 27 '17 at 13:10
  • In-browser JavaScript can't read or write local files on the user's computer for obvious security reasons. What are you actually trying to accomplish here and why? – David Sep 27 '17 at 13:11
  • You can create local blobs and let the user save or download. https://stackoverflow.com/questions/13405129/javascript-create-and-save-file – Aritra Chakraborty Sep 27 '17 at 13:12
  • Your update to the question makes no sense. You might be confusing the term "local". A "local" file would be local to the *user's* computer, on which the browser is running. If you're running a *server* of some kind then you would be tracking this information in your server-side code. – David Sep 27 '17 at 14:21
  • And that is exactly what is happening. I do not see confusion. There is no server, there is html file with one js script included runing on my local computer. And files I want to edit are on the same computer. – somik07 Sep 27 '17 at 20:11

1 Answers1

-1

You can do with this

var data = {"Name":"first name","age":30}
var serializedData = JSON.stringify(data);          
var link = document.getElementById('downloadlink');
link.href = makeTextFile(serializedData);
document.getElementById('downloadlink').click();
Vishal Kamal
  • 1,104
  • 2
  • 10
  • 35