5

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();
1
  • 3
    ActiveX stuff only works in Internet Explorer. Commented Apr 2, 2013 at 13:20

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Always welcome....!!!
How to make it work on other browsers like chrome, FF and safari ?
1

Exactly, ActiveX only works in Internet Explorer. And you need define a function and call this.

<script>
    function wtf() {
        set fso = CreateObject("Scripting.FileSystemObject");
        set s = fso.CreateTextFile("C:\test.txt", True);
        s.writeline("HI");
        s.writeline("Bye");
        s.writeline("-----------------------------");
        s.Close();
    }
</script>

<body onload="wtf()">

3 Comments

jajaja wtf = write to file jeejeje
How to make it work on other browsers like chrome, FF and safari ?
In FF, Chrome, Others. you can use HTML5 (its supported) check this: w3.org/TR/file-writer-api

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.