【问题标题】:Phonegap Cordova with PDFjs securtiy policy error带有 PDFjs 安全策略错误的 Phonegap Cordova
【发布时间】:2017-02-09 07:14:01
【问题描述】:

我正在使用 Adob​​e PhoneGap 6.3.3,我正在尝试在带有 PFDjs 的混合 android 应用程序中显示 PDF。在浏览器中显示pdf,使用PhoneGap App Develover从手机安装它不起作用。在控制台中我有这个消息:

Content Security Policy has been modified to be: <meta
 http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: 'un
safe-inline' https://ssl.gstatic.com * ws:;style-src 'self' 'unsafe-inline' data
: blob:;media-src *;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">

我使用以下代码从互联网上阅读了 pdf:

    var url = 'http://www.example.com/foo.pdf';
    getBinaryData(url); //call this fn on page load 

    var callGetDocument = function (response) {
          // body...
          PDFJS.getDocument(response).then(function getPdfHelloWorld(_pdfDoc) {
            console.log('File caricato');
            pdfFile = _pdfDoc;
            openPage(pdfFile, currPageNumber, 1);

          });
        }


    var getBinaryData = function (url) {
        console.log('getBinaryData');
        // body...
        var xhr = new XMLHttpRequest();

        xhr.open('GET', url, true);
        xhr.responseType = 'arraybuffer';
        xhr.onload = function(e) {
            //binary form of ajax response,
            callGetDocument(e.currentTarget.response);
        };

        xhr.onerror = function  () {
            // body...
            console.log("xhr error");
        }

        xhr.send();
    }

我仍然在config.xml 中插入&lt;allow-navigation href="http://*/*" /&gt;。 你能帮帮我吗?

【问题讨论】:

    标签: android cordova pdf phonegap-plugins pdfjs


    【解决方案1】:

    解决办法是here

    这是一个 CSP(内容安全策略)问题。 我从this 站点创建了一个 CSP,并将元标记插入到我的index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 2018-02-14
      • 2015-09-17
      相关资源
      最近更新 更多