Cordova iOS和Android webview stream pdf下载

时间:2017-05-18 05:44:01

标签: php android ios cordova inappbrowser

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

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 links没有任何作用。

这是我的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>

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

0 个答案:

没有答案