无法在android中的inappbrowser中启动pdf文件

use*_*988 9 javascript jquery phonegap-plugins cordova ibm-mobilefirst

当用户点击链接时,我需要在inappbrowser中显示pdf.它在ios中工作正常,但没有在android上工作.我正在为我的项目使用IBM worklight.以下是我使用过的代码:

window.open("pdfURL","_blank","location=yes");
Run Code Online (Sandbox Code Playgroud)

在ios中,inappbrowser启动并显示pdf,但在android中,inappbrowser启动但没有显示内容

Ida*_*dar 16

与具有内置PDF查看器的iOS不同,Android的webview没有内置的PDF查看器.
这就是它在Android中失败的原因.

您在Android中有2个选择:

  1. 通过将文件存储在远程服务器上并使用以下方式重定向用户,使用Google Docs查看该文件:window.open(encodeURI('https://docs.google.com/gview?embedded=true&url=http://www.your-server.com/files/your_file.pdf'), '_blank', 'location=yes,EnableViewPortScale=yes');

  2. 或者使用Cordova插件.例如这个(你可以在谷歌搜索更多).为此,您需要了解如何在Worklight中创建Cordova插件.

您可以在此处阅读更多选项:Phonegap InAppBrowser display pdf 2.7.0


小智 6

尝试使用

window.open('pdfURL',"_system","location=yes,enableViewportScale=yes,hidden=no");
Run Code Online (Sandbox Code Playgroud)

using_system将下载文件并在系统应用程序(如 Chrome 或其他 PDF 查看器)中打开它。


Mar*_*gon 5

使用 uriEncodeComponent(link) 和https://docs.google.com/viewer?url= link

Doc、Excel、Powerpoint 和 pdf 均受支持。

在应用程序浏览器中使用 cordova。

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
        }

            $("body").on("click",function(e){
           var clicked = $(e.target);
         if(clicked.is('a, a *'))
       {
             clicked = clicked.closest("a");
             var link = clicked.attr("href");
            if(link.indexOf("https://") !== -1)
           {
               if(true) //use to be able to determine browser from app
                 {
                    link = "http://docs.google.com/viewer?url=" +  encodeURIComponent(link) + "&embedded=true";
             }

                 window.open(link, "_blank", "location=no,toolbar=no,hardwareback=yes");
                return false;
            }
    }
    });
Run Code Online (Sandbox Code Playgroud)