ReferenceError: ActiveXObject is not defined in Chrome and Mozilla

Suraj Anand picture Suraj Anand · Jul 21, 2017 · Viewed 17.9k times · Source

I am having a lot of difficulty attempting to solve a ReferenceError:

ActiveXObject is not defined in Google Chrome.

function WriteToFile()
{
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var s = fso.CreateTextFile("/var/www/html/nodejsphp/Test.txt",true);
  s.WriteLine('messages');
  console.log("contents of file now'some sampletext'");
  s.Close();
}

Any idea where to begin?

Answer

T.J. Crowder picture T.J. Crowder · Jul 21, 2017

That's because Google Chrome and Mozilla Firefox (and Microsoft Edge) don't support ActiveXObject, and never have, and never will. ActiveX has no place in modern web browsers.

Only IE supports ActiveXObject, and even then, more recent versions of IE only support it with a subset of objects (I don't think FileSystemObject is one of them).

As for creating a text file on the local machine's file system from a web page: Nope, you can't do that. (Except in old versions of IE with security disabled.)