2010-04-29 4 views
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에 있었기 때문에 사용할 수 없었습니다.

+0

다음은 제가 게시하지 않은 자원 중 일부입니다. 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/en/Code_snippetsMiscellaneous#Saving_the_current_web_page_to_a_local_file – Nathan

답변

1

나는 당신이 this을 원한다고 생각하지만 귀하의 질문은 매우 모호합니다.

+0

감사합니다. 나는 그것을 시도하고 있었지만, 나는 잘못된 것을하고 있었다고 생각한다. – Nathan