2012-02-23 6 views
2

iOS phonegap (v 1.3) 앱을 빌드하고 있습니다. 그 페이지에서 나는 .pptx 파일을 다운로드하는 버튼을 주었다.Phonegap iOS 앱에서 파일보기/다운로드

<a href="'+downloadUrl+'" target="_blank">Download file</a> 

버튼의 href는 내 웹 사이트의 다운로드 링크를 가리 킵니다. 따라서 링크를 클릭하면 파일이 자동으로 다운로드됩니다.
링크를 클릭하면 파일이 다운로드되지만 동일한보기로 열립니다. pptx의 모든 슬라이드는 다른 슬라이드 아래에 있으며 전체 화면을 차지합니다. 내 앱을 죽이고 다시 시작하는 것 외에는 내 앱으로 돌아갈 방법이 없습니다. 나는 target = "_blank", "_tab", 아무 것도 작동하지 않았고, 모든 결과는 화면상의 슬라이드와 비슷한 결과를 낳았고, 내 앱으로 되돌아 갈 방법이 없었습니다.

.pptx 파일이 다른보기에서 열리거나 더 열리지 않고 전혀 열리지 않고 저장할 수 있습니까 (안드로이드 같이)? pls 도움이됩니다.

답변

1

에서 살펴 샘플 코드를 따라 수도 있겠죠.

은 index.html을에 바로 </head> 태그 위에 주어진 코드를 포함

<script type="text/javascript" charset="utf-8"> 
     // Wait for Cordova to load 
    document.addEventListener("deviceready", onDeviceReady, false); 
    // Cordova is ready 
    function onDeviceReady() { 
     alert("Going to start download"); 
     downloadFile(); 
    } 

    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(
                       "http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf", 
                       sPath + "theFile.pdf", 
                       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("deviceready"); 
     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); 
    } 

    </script> 

참조 : - Blog Post