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

发布于 2025-01-08 13:06:36 字数 467 浏览 0 评论 0原文

我正在构建一个 iOS PhoneGap(v 1.3) 应用程序。在该页面上,我给出了一个下载 .pptx 文件的按钮。

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

该按钮的 href 指向我网站上的下载链接。因此,单击链接应该会自动下载该文件。
发生的情况是,单击链接后,文件会被下载,但会在同一视图中打开。 pptx 的所有幻灯片都一张一张地放在另一张下面,并且占据整个屏幕。除了终止我的应用程序并重新启动之外,没有其他方法可以返回我的应用程序。我尝试了 target =“_blank”、“_tab”,没有任何效果,一切都会导致与屏幕上的幻灯片类似的行为,并且我无法返回到我的应用程序。

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

Im building an iOS phonegap(v 1.3) app. In that on a page i have given a button to download a .pptx file.

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

The href of the button points to a download link on my website. So clicking on the link should automatically download the file.
Whats happening is that on clicking on the link, the file is downloaded but it opens up in the same view. All slides of the pptx come one below the other and they occupy the full screen. There is no way to go back to my app, other than killing my app and restarting. I tried target = "_blank", "_tab", nothing works, everything results in a similar behavior with the slides on the screen and no way for me to go back to my app.

Can i do something so that the .pptx file opens in another view, or better, not opens at all and just gets saved(like in android)? pls help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说好的呢 2025-01-15 13:06:37

我想你可以看看这个插件

PhoneGap 插件用于下载 URL

I guess you could take a look at this plugin

PhoneGap plugin for downloading URL

无所谓啦 2025-01-15 13:06:37

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

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

请参阅:- 博客文章

For downloading and displaying a file, follow the sample code.

Include the given code just above the </head> tag in your 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>

Refer :- Blog Post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文