0
無視我以前的編輯前的帖子。重新審視我需要做的事情。這是目前我在做什麼: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIScriptableIO更改保存目錄
downloadFile: function(httpLoc) {
try {
//new obj_URI object
var obj_URI = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService).
newURI(httpLoc, null, null);
//new file object
//set file with path
obj_TargetFile.initWithPath("C:\\javascript\\cache\\test.pdf");
//if file doesn't exist, create
if(!obj_TargetFile.exists()) {
obj_TargetFile.create(0x00,0644);
}
//new persitence object
var obj_Persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
createInstance(Ci.nsIWebBrowserPersist);
// with persist flags if desired
const nsIWBP = Ci.nsIWebBrowserPersist;
const flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
obj_Persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
//save file to target
obj_Persist.saveURI(obj_URI,null,null,null,null,obj_TargetFile);
return true;
} catch (e) {
alert(e);
}
},//end downloadFile
正如你可以看到目錄中有硬編碼的,我要保存PDF文件打開在活動選項卡相對臨時目錄,或任何地方,是超出的方式足以讓用戶不會絆倒並刪除它。我將嘗試使用File I/O,我的印象是我所尋找的是可腳本化的文件I/O,因此被禁用。
下面是我一直在使用的一些資源,它不會讓我發佈。 https://developer.mozilla.org/en/Code_snippets/Downloading_Files https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Streams https://developer.mozilla.org/en/NsIIOService http://www.oxymoronical.com/experiments/apidocs/interface/nsIInputStreamPump https://developer.mozilla.org/zh/Code_snippetsMiscellaneous#Saving_the_current_web_page_to_a_local_file – Nathan 2010-04-29 15:21:14