[javascript] create a text file using javascript

I am using the following code to create a text file using javascript and it's not working

<html>
    <head>
        <script language="javascript">
            function WriteToFile()
            { 
                var txt = new ActiveXObject("Scripting.FileSystemObject");
                var s = txt.CreateTextFile("11.txt", true);
                s.WriteLine('Hello');
                s.Close();
             }
         </script>
    </head>
   <body onLoad="WriteToFile()">
   </body>
</html>

This question is related to javascript file activex

The answer is


That works better with this :

var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();

http://msdn.microsoft.com/en-us/library/5t9b5c0c(v=vs.84).aspx


You have to specify the folder where you are saving it and it has to exist, in other case it will throw an error.

var s = txt.CreateTextFile("c:\\11.txt", true);

From a web page this cannot work since IE restricts the use of that object.


Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to file

Gradle - Move a folder from ABC to XYZ Difference between opening a file in binary vs text Angular: How to download a file from HttpClient? Python error message io.UnsupportedOperation: not readable java.io.FileNotFoundException: class path resource cannot be opened because it does not exist Writing JSON object to a JSON file with fs.writeFileSync How to read/write files in .Net Core? How to write to a CSV line by line? Writing a dictionary to a text file? What are the pros and cons of parquet format compared to other formats?

Examples related to activex

Microsoft Excel ActiveX Controls Disabled? IE11 prevents ActiveX from running What is the difference between "Form Controls" and "ActiveX Control" in Excel 2010? create a text file using javascript How do I resolve "Run-time error '429': ActiveX component can't create object"? ActiveXObject creation error " Automation server can't create object" How to launch an application from a browser? How to Enable ActiveX in Chrome? Print directly from browser without print popup window ActiveX component can't create object