ActiveXObject is not defined and cannot find a variable: ActiveXObject

I want to create a text file in local mode, when I look at a button click in Google Chrome, it shows an error, for example, ActiveXObject is not defined , and when I look at a button click in safari, it shows an error, for example it cannot find a variable: ActiveXObject . anyone can help me. How can I achieve and create a .Thanq file

<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()'> 
+11
javascript sencha-touch-2
Jun 19 '12 at 13:08
source share
3 answers

ActiveXObject is only available in the IE browser. Therefore, every other user agent will throw an error

In a modern browser, you can instead use the File API or API to write files (currently only implemented in Chrome )

+15
Jun 19 2018-12-12T00:
source share

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

There is no built-in cross-browser way to write to the file system without using plugins, even a draft API file provides read-only access.

If you want to work with a cross platform, you need to look at things like signed Java applets (bearing in mind that this will only work on platforms for which the Java runtime is available).

+8
Jun 19 2018-12-12T00:
source share

A web application can request access to an isolated file system by calling window.requestFileSystem() . It 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 details here .

+2
Jun 19 '12 at 13:28
source share



All Articles