[javascript] ActiveXObject is not defined and can't find variable: ActiveXObject

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()'>

This question is related to javascript sencha-touch-2

The answer is


ActiveXObject is non-standard and only supported by Internet Explorer on Windows.

There is no native cross browser way to write to the file system without using plugins, even the draft File API gives read only access.

If you want to work cross platform, then you need to look at such things as signed Java applets (keeping in mind that that will only work on platforms for which the Java runtime is available).


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)


A web app can request access to a sandboxed file system by calling window.requestFileSystem(). Works in Chrome.

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
var fs = null;

window.requestFileSystem(window.TEMPORARY, 1024 * 1024, function (filesystem) {
    fs = filesystem;
}, errorHandler);

fs.root.getFile('Hello.txt', {
    create: true
}, null, errorHandler);

function errorHandler(e) {
  var msg = '';

  switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
      msg = 'QUOTA_EXCEEDED_ERR';
      break;
    case FileError.NOT_FOUND_ERR:
      msg = 'NOT_FOUND_ERR';
      break;
    case FileError.SECURITY_ERR:
      msg = 'SECURITY_ERR';
      break;
    case FileError.INVALID_MODIFICATION_ERR:
      msg = 'INVALID_MODIFICATION_ERR';
      break;
    case FileError.INVALID_STATE_ERR:
      msg = 'INVALID_STATE_ERR';
      break;
    default:
      msg = 'Unknown Error';
      break;
  };

  console.log('Error: ' + msg);
}

More info here.