2013-01-18 15 views
2

Phonegap의 소스 파일을 다운로드하거나 다운로드하는 방법을 알아 보겠습니다.Phonegap html 파일 다운로드 및 바꾸기 (소스)

<!DOCTYPE html> 
<html> 
    <head> 
     <title></title> 
     <script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script> 
     <script type="text/javascript"> 
       function onBodyLoad() 
      { 
       document.addEventListener("deviceready", onDeviceReady, false); 
      } 

      function downloadFile(){ 
       window.requestFileSystem(
             LocalFileSystem.PERSISTENT, 0, 
             function onFileSystemSuccess(fileSystem) { 
             fileSystem.root.getFile(
                   "dummy.html", {create: true, exclusive: false}, 
                   function gotFileEntry(fileEntry){ 
                   var sPath = fileEntry.fullPath.replace("dummy.html",""); 
                   var fileTransfer = new FileTransfer(); 
                   fileEntry.remove(); 

                   fileTransfer.download(
                         "https://dl.dropbox.com/u/xxxxx/index_2.html", 
                         sPath + "index_aerosoft.html", 
                         function(theFile) { 
                         console.log("download complete: " + theFile.toURI()); 
                         showLink(theFile.toURI()); 
                         }, 
                         function(error) { 
                         console.log("download error source " + error.source); 
                         console.log("download error target " + error.target); 
                         console.log("upload error code: " + error.code); 
                         } 
                         ); 
                   }, 
                   fail); 
             }, 
             fail); 

      } 

      function showLink(url){ 
       alert(url); 
       var divEl = document.getElementById("ready"); 
       var aElem = document.createElement("a"); 
       aElem.setAttribute("target", "_blank"); 
       aElem.setAttribute("href", url); 
       aElem.appendChild(document.createTextNode("Ready! Click To Open.")) 
       divEl.appendChild(aElem); 

      } 


      function fail(evt) { 
       console.log(evt.target.error.code); 
      } 

      function onDeviceReady() 
      { 
       downloadFile(); 
      } 

      </script> 
    </head> 
    <body onload="onBodyLoad()"> 
      <br /> 
      <p> 
      DOWNLOADING FILE...<br /> 
      <span id="ready"></span> 
      </p> 
      </body> 
</html> 

파일을 다운로드하여 액세스 할 수 있지만 Phonegap의 'www'폴더에 다운로드 경로를 설정할 수 있습니까? 아니면 파일의 경로가

엑스 코드 콘솔이 날 file://localhost/var/mobile/Applications/1AE34410-C57E-4896-8616-042E386552E0/Documents/index_2.html

알려줍니다 (그래서 난 그 길에 연결할 수) 내가 어떻게 든 링크 할 수 있습니다 알아낼 방법? 안드로이드 자산 폴더 읽기 전용되고 HTML 당신이 장소를 작성했기 때문에 자바를 프로그래밍 할 수있는 경우

당신은 소스 코드를 대체 할 수
+3

앱에 번들로 제공되는 파일을 덮어 쓸 수 없습니다. 영구 저장 장치의 위치에만 쓸 수 있습니다. – codemonkey

답변

4

...
... 는 내가 HTML 파일을 극복 제안 자산에서이
에서 코드를 실행 한 후 sdcard에 당신은

다음을 수정할 수 있습니다하지만 난 (Dreamweaver에서) 폰갭 빌드에서 이런 짓을 그리고 그것은 나를 위해 일한 : 다음

// retrive html data as String in Var : MY_Data 
window.localStorage.setItem("mydiv_update", My_Data); 
document.getElementById("your_div").innerHtml = My_Data; 

때마다 일을 e 페이지가로드 중입니다. window.localStorage.getItem("mydiv_update")이 있는지 확인하십시오. 그렇다면 div의 innetHTML을 변경하십시오.

if(window.localStorage.getItem("mydiv_update")){ 
    document.getElementById("your_div").innerHtml = window.localStorage.getItem("mydiv_update"); 
} 

하고 잊지 마세요 저장 권한 :

권한


안드로이드

응용 프로그램/고해상도/XML/config.xml에이 같은 :

,210
<plugin name="File" value="org.apache.cordova.FileUtils" /> 
<plugin name="FileTransfer" value="org.apache.cordova.FileTransfer" /> 

응용 프로그램/AndroidManifest.xml에 :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

우루루

은 어떤 권한이 필요하지 않습니다.


블랙 베리 WebWorks

www /에서 plugins.xml :

<plugin name="File" value="org.apache.cordova.file.FileManager" /> 
<plugin name="FileTransfer" value="org.apache.cordova.http.FileTransfer" /> 

www /에서 config.xml 파일 :

<feature id="blackberry.io.file" required="true" version="1.0.0.0" /> 
<feature id="blackberry.utils" required="true" version="1.0.0.0" /> 
<feature id="blackberry.io.dir" required="true" version="1.0.0.0" /> 
<rim:permissions> 
    <rim:permit>access_shared</rim:permit> 
</rim:permissions> 

iOS :
config.XML :

<plugin name="File" value="CDVFile" /> 
<plugin name="FileTransfer" value="CDVFileTransfer" /> 

웹 OS : 어떤 권한이 필요하지 않습니다
.


윈도우 폰 : 없음 권한이 필요하지 않습니다
.

관련 문제