ActiveXObject is not defined and can't find variable: ActiveXObject

Ramesh Lamani picture Ramesh Lamani · Jun 19, 2012 · Viewed 203.6k times · Source

i want to create text file in local, when i browse in Google chrome click of the button it is showing error like ActiveXObject is not defined and when i browse in safari click of the button it is showing error like can't find variable: ActiveXObject . any one can help me.how can i achieve and create file .Thanq

<script>
      function createFile() {    
      var object = new ActiveXObject("Scripting.FileSystemObject");       
      var file = object.CreateTextFile("C:\\Hello.txt", true);
      file.WriteLine('Hello World');
      alert('Filecreated');
      file.WriteLine('Hope is a thing with feathers, that perches on the soul.'); 
      file.Close();
      }
    </script>
<input type="Button" value="Create File" onClick='createFile()'>

Answer

Fabrizio Calderan picture Fabrizio Calderan · Jun 19, 2012

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

On modern browser you could use instead File API or File writer API (currently implemented only on Chrome)