2016-09-30 65 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