How can I create a text file using JavaScript?

anandh199g picture anandh199g · Apr 2, 2013 · Viewed 26.2k times · Source

I am trying to create a text file using JavaScript. I have tried the following code, but this didn’t work. What is the solution?

var fso, file;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.CreateTextFile("c:\\Mytest\test.txt");
file.Close();

Answer

Prasath K picture Prasath K · Apr 2, 2013

You cannot do it using ActiveXObject as it works only in Internet Explorer... Have a look on File System APIs of HTML5 which may help you.