开发者

Browser - file writer extension?

Is there any chrome or firefox ex开发者_运维知识库tension that allows javascript to create write files in client's PC?


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.


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜