Php Cordova iOS和Android webview流pdf下载

Php Cordova iOS和Android webview流pdf下载,php,android,ios,cordova,inappbrowser,Php,Android,Ios,Cordova,Inappbrowser,我有一个Cordova项目,其中inAppBrowser插件用于加载php webapp。在该应用程序中,使用以下php代码动态生成指向强制下载pdf(download.php?id=xxxxx)的链接: header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='

我有一个Cordova项目,其中inAppBrowser插件用于加载php webapp。在该应用程序中,使用以下php代码动态生成指向强制下载pdf(download.php?id=xxxxx)的链接:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
我的Cordova应用程序不处理那些download.php?id=xxxxx链接

这是我的index.html:

<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>MyApp</title>
    </head>
    <body>
    <script type="text/javascript">
        document.addEventListener('deviceready', function() {
            var url = 'http://sub.domain.com/app/en/login/' // change to whatever you want
            cordova.InAppBrowser.open(url, '_blank', 'location=no,zoom=no');
        }, false)
    </script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

MyApp
document.addEventListener('deviceready',function(){
var url='1〕http://sub.domain.com/app/en/login/“//更改为您想要的任何内容
打开(url,“_blank”,“location=no,zoom=no”);
},错)

如何使下载在此Cordova应用程序中工作?如果无法下载,是否可以让用户“查看”pdf?

是的,WebView不下载文件。在iOS上,您可以直接查看它。在Android上,您可以使用_系统选项,这样它应该启动一个intent,以便其他应用程序打开它。@jcesarmobile似乎不起作用。尝试了target=“\u system”和,但无效。还有其他选择吗?对不起,我不清楚我的意思。您必须提供实际文件,而不是提供强制下载。通过使用_系统,我指的是inAppBroser(
cordova.InAppBrowser.open(fileUrl,“_系统”);
),但没有意识到你已经在InAppBrowser上显示了你的网站,所以这对Android不起作用。您可以使用loadstart事件,检查url上是否有download.php,然后打开一个新的inAppBrowserwindow@jcesarmobile谢谢你的信息。你能给出一个答案吗?你能用代码来说明你的解决方案吗?谢谢@如果你想在cordova应用程序中寻找与下载pdf功能相关的答案并显示pdf供查看,那么我想你应该使用文件和文件开启器插件。建议您参考此github repo-您可以从服务器下载pdf并显示在应用程序中的工作示例应用程序。请看一下自述。它应该能帮你