Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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()'>
like image 819
Ramesh Lamani Avatar asked Jun 19 '12 13:06

Ramesh Lamani


People also ask

How do you fix ActiveXObject is not defined?

Inside Internet options, go to the Advanced tab and uncheck the boxes associated with Disable script debugging (Internet Explorer) and Disable script debugging (Other). Hit the Appy button to save the changes and reload the web page that was previously showing the ActiveXObject is not defined error.

How do you define ActiveXObject?

The ActiveXObject object is used to create instances of OLE Automation objects in Internet Explorer on Windows operating systems. Several applications (Microsoft Office Word, Microsoft Office Excel, Windows Media Player, ...) provide OLE Automation objects to allow communication with them.

What is ActiveXObject in Javascript?

An ActiveX object is an instance of a class that exposes properties, methods, and events to ActiveX clients. ActiveX objects support the COM. An ActiveX component is an application or library that is capable of creating one or more ActiveX objects.


3 Answers

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)

like image 190
Fabrizio Calderan Avatar answered Oct 21 '22 16:10

Fabrizio Calderan


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).

like image 45
Quentin Avatar answered Oct 21 '22 16:10

Quentin


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.

like image 20
jasssonpet Avatar answered Oct 21 '22 18:10

jasssonpet