0

I have used below code:

var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("test.txt", true);
    for(var j=1;j<9;j++)
    {
        s.WriteLine('Test'  + j);
    }
    s.Close();

Getting below error when I run above code: ReferenceError: ActiveXObject is not defined

6
  • What are you using to run this code? Commented May 24, 2018 at 8:57
  • Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. In other words, modern browsers don't support ActiveXObjects anymore. Commented May 24, 2018 at 8:58
  • Which browser are you using? Commented May 24, 2018 at 8:58
  • You could try toying with data:url's or just use a serverside script to create the file and offer it for download. Certain versions of IE also support: window.navigator.msSaveBlob() which can be used to generate text files. Commented May 24, 2018 at 9:01
  • I have used Chrome and Mozila browser Commented May 24, 2018 at 9:01

2 Answers 2

1

ActiveXObject is available only on IE browser. So every other useragent will throw an error

On other browsers, you could any of this:

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

3 Comments

Moreover, even with Internet Explorer, this will not work unless you severely reduce the security options.
@Captain Jack: Code not working on IE browser. Also I have read documentation on File API but in this documentation there is no code to write file.
What is the issue that you are having now?
0

try this This will work only on IE8

 <SCRIPT LANGUAGE="JavaScript">
 function WriteToFile(passForm) {

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

</head>

<body>
<p>To sign up for the Excel workshop please fill out the form below:
</p>
<form onSubmit="WriteToFile(this)">
Type your first name:
<input type="text" name="FirstName" size="20">
<br>Type your last name:
<input type="text" name="LastName" size="20">
<br>
<input type="submit" value="submit">
</form> 

cridte @667776 @Faraona Faraona

1 Comment

This will work in IE8 or earlier only (createObject is not supported since IE9).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.