Browser - file writer extension?

故事扮演 提交于 2019-12-23 02:17:37

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/4824017/browser-file-writer-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!