在Phonegap iOS应用程序中查看/下载文件

在Phonegap iOS应用程序中查看/下载文件,ios,cordova,mobile-safari,download,Ios,Cordova,Mobile Safari,Download,我正在构建一个iOS phonegap(v1.3)应用程序。在这一页中,我提供了一个下载.pptx文件的按钮 <a href="'+downloadUrl+'" target="_blank">Download file</a> 按钮的href指向我网站上的下载链接。因此,单击链接应自动下载文件。 发生的事情是,点击链接,文件被下载,但它在相同的视图中打开。pptx的所有幻灯片一张接一张,占据整个屏幕。除了关闭我的应用程序并重新启动外,没有办法返回到我的应用程序。我

我正在构建一个iOS phonegap(v1.3)应用程序。在这一页中,我提供了一个下载.pptx文件的按钮

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

按钮的href指向我网站上的下载链接。因此,单击链接应自动下载文件。
发生的事情是,点击链接,文件被下载,但它在相同的视图中打开。pptx的所有幻灯片一张接一张,占据整个屏幕。除了关闭我的应用程序并重新启动外,没有办法返回到我的应用程序。我尝试了target=“\u blank”、“\u tab”,什么都不起作用,一切都会导致屏幕上的幻灯片出现类似的行为,我无法返回到我的应用程序


我可以做些什么,使.pptx文件在另一个视图中打开,或者更好,根本不打开,只是保存(就像在android中)?请帮忙。

我想你可以看看这个插件


要下载和显示文件,请遵循示例代码

在index.html中的
标记上方包含给定代码

<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>

//等待Cordova加载
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//科尔多瓦准备好了
函数ondevicerady(){
警报(“即将开始下载”);
下载文件();
}
函数下载文件(){
window.requestFileSystem(
LocalFileSystem.PERSISTENT,0,
函数onFileSystemsSuccess(文件系统){
fileSystem.root.getFile(
“dummy.html”{create:true,exclusive:false},
函数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”,
函数(文件){
log(“下载完成:+theFile.toURI());
showLink(theFile.toURI());
},
函数(错误){
log(“下载错误源”+错误源);
log(“下载错误目标”+错误目标);
日志(“上传错误代码:+错误代码”);
}
);
},
失败);
},
失败);
}
函数showLink(url){
警报(url);
var divEl=document.getElementById(“deviceready”);
var aElem=document.createElement(“a”);
aElem.setAttribute(“目标”,“空白”);
setAttribute(“href”,url);
appendChild(document.createTextNode(“准备好了!单击打开”))
附属物儿童(aElem);
}
功能失效(evt){
log(evt.target.error.code);
}
参考:-