2016-09-30 113 views
1

我正在使用Adobe PhoneGap 6.3.3,我正尝试在PFDjs的混合Android应用中显示PDF。在浏览器中,pdf是diplayed的,从PhoneGap应用程序开发者手机中删除,它不起作用。在控制台我有这样的消息:Phonegap Cordova与PDFjs安全策略错误

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(); 
    } 

我还在​​3210插入<allow-navigation href="http://*/*" />。 你能帮我吗。

回答

0

的解决方案是here

这是一个CSP(内容安全政策)问题。 从this网站我创建了一个CSP,并且将meta标签插入我的index.html