1

Need expert ideas how to Create and Write to .txt file on JavaScript. I am using below code it works fine with IE but not on Chrome with error as "ActiveXObject" undefined. "ActiveXObject" related to IE specific not supported on Chrome.

var myObject = new ActiveXObject("Scripting.FileSystemObject");

I have checked few comments related to similar issue and i also tried using below options:

Option-1:

set fso = CreateObject("Scripting.FileSystemObject");  
set s = fso.CreateTextFile("C:\test.txt", True);

Option-2:

var reader = new FileReader();
reader.onload = function(e) 

Still issue persists. Need support how to write code in javascript which can be Browser independent (can execute on IE, CHrome and FF) .

Lux
  • 17,835
  • 5
  • 43
  • 73
Sunil
  • 11
  • 2
  • some options but not working - http://stackoverflow.com/questions/36216496/javascript-open-a-file-from-localdisk?lq=1 – Sunil Jun 01 '16 at 12:09
  • Possible duplicate of [How to generate and prompt to save a file from content in the client browser?](http://stackoverflow.com/questions/18690450/how-to-generate-and-prompt-to-save-a-file-from-content-in-the-client-browser) – tafa Jun 01 '16 at 13:30

1 Answers1

0

Try this but this will work only on IE

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();
 }
<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>
Harshil Kulkarni
  • 411
  • 5
  • 20
  • Required how to write so it will work on all Browser. Mainly i required for Chrome browser, IE is option for my requirement. – Sunil Jun 01 '16 at 12:33
  • How to create and write file for CHROME browser. any different method/mechanism specific to Chrome? In blogs i can find only support of Windows IE not for Chrome support. – Sunil Jun 01 '16 at 12:49