1

是否有任何鉻或Firefox擴展,允許JavaScript創建寫在客戶端的PC文件?瀏覽器 - 文件編寫器擴展?

+1

將文件寫入客戶機(除了cookie)通常被認爲是一個主要的安全問題。當然黑客似乎從來沒有遇到過很多麻煩...... – DeveloperChris 2011-01-28 02:16:17

+0

類似:http://stackoverflow.com/questions/4771758/how-to-generate-a-file-for-download-in-a-google-chrome -extension – serg 2011-01-28 02:29:03

回答

1

你想做什麼?

HTML5有一個File API。這是最好的解決方案,因爲它允許選擇文件完全由用戶控制。

如果您需要,您可以製作自己的NPAPI插件,該插件公開自己的腳本(又名NPRuntime),並代表頁面中的Javascript執行本地本地文件操作。或者,在IE中,new ActiveXObject("Scripting.FileSystemObject")可能會產生FileSystemObject(取決於ActiveX設置)。但請不要。

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