I want from JavaScript to write data to a file. Found an example, but it does not work for me, on the operator:

var fso = new ActiveXObject("Scripting.FileSystemObject"); 

In the debugger of the browser IE11 I see the inscription:

"Cannot create object with object programming server"

What does it mean? How do I solve this problem?

3 answers 3

Allow JS to interact with FS would be terrified. Any "hacker" will consider it his duty to try to "secretly, in the style of Assassin's Creed," download the muck, writing on the screen very offensive words :)
And this is at least, because the authors of serious software and so exploit the holes in browsers, with such an opportunity in general will be rampant.

The browser can be offered to download the file through the header or download attribute.
Plus - JS does not need to be written to files, it is created for another. And if the architecture requires such actions from him, this is a good reason to think about the proper planning of the architecture itself.

  • JS for another created? lucky that the creators of mongodb and nodejs didn't know about it;) - PashaPash
  • Not understood. About the "download" read, but this is not what I need. But I need to read the data from the file (coordinates of several points), build paths between them using the Yandex Maps API, and then write the times of these paths to another file. And how do I change the architecture? - Ali58
  • @PashaPash, That ports to other branches of evolution, the canonical JS does not need it. - user31688
  • @Alexander, You can only read data from the server, calculate the route there too (I don’t know for sure, didn’t work with their API), then just offer to save the file with the header. In the extreme case, send the calculation results to the server and let the server again offer to save the file. There is a FileAPI, but it allows you to work with files that the user selects, but you cannot save. Well, or I'm behind the times :) - user31688

This means that this hole has long been fixed.

Use file download instead.

  • one
    Do not quite understand. "Hole fixed" - this, apparently, banned the operation "new ActiveXObject"? And how exactly to use file downloading instead? - Ali58
  • @ Alexander, use Blob and <a download="smth.bin">...</a> . - Qwertiy

Scripting.FileSystemObject marked as "unsafe." The ability to "take and write data to a file" on the client side is a security hole in the browser. Therefore, the ability to create is disabled by default. To enable, you will have to change the security settings for the current zone:

Tools → Internet Options → Security → Custom Level → ActiveX controls and Plugins → Security options → Enabled or Prompt.

But it is better not to do this - it will work only in IE, and only when changing the security settings.