pareshm pareshm - 1 year ago 42
HTML Question

Is it possible to write data to file using only JavaScript?

I want to Write Data to existing file using JavaScript.
I don't want to print it on console.
I want to Actually Write data to

I Read many answered question but every where they are printing on console.
at some place they have given code but its not working.
So please can any one help me How to actually write data to File.

I referred the code but its not working:
its giving error:

Uncaught TypeError: Illegal constructor

on chrome and

SecurityError: The operation is insecure.

on Mozilla

var f = "sometextfile.txt";

writeTextFile(f, "Spoon")
writeTextFile(f, "Cheese monkey")
writeTextFile(f, "Onion")

function writeTextFile(afilename, output)
var txtFile =new File(afilename);

So can we actually write data to file using only Javascript or NOT?
Please Help Me
Thanks in advance

Answer Source

Some suggestions for this -

  1. If you are trying to write a file on client machine, You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write file.
  2. If you are trying to save it on your server then simply pass on the text data to your server and execute the file writing code using some server side language.
  3. To store some information on the client side that is considerably small, you can go for cookies.
  4. Using the HTML5 API for Local Storage.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download