How can I create a text file using JavaScript?
26,530
Solution 1
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.
Solution 2
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()">
Comments
-
anandh199g over 3 years
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();