Moe Sweet
Moe Sweet

Reputation: 3721

Browser - file writer extension?

Is there any chrome or firefox extension that allows javascript to create write files in client's PC?

Upvotes: 1

Views: 2050

Answers (2)

Bhavik Goyal
Bhavik Goyal

Reputation: 2796

var file = Components.classes["@mozilla.org/filelocal;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("Pathforfile");

file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance( Components.interfaces.nsIFileOutputStream );
outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
var output="Texttowriteinfile";                                     
var result = outputStream.write( output, output.length );
outputStream.close();

Upvotes: 1

ephemient
ephemient

Reputation: 204668

What do you want to do?

HTML5 has a File API. This is the best solution because it allows selection of the file to be wholly under user control.

If you must, you can make your own NPAPI plugin which exposes itself to scripting (aka NPRuntime) and performs native local file operations on behalf of Javascript in the page. Or, in IE, new ActiveXObject("Scripting.FileSystemObject") may yield a FileSystemObject (depending on ActiveX settings). But please don't.

Upvotes: 1

Related Questions