Blocked frame with source "http: // localhost: 8084" from access to frame with transverse origin

I am trying to print a pdf file created by jspdf and loaded in an iframe, but I get this error message:

"DOMException: Blocked frame with source" http: // localhost: 8084 "from accessing a frame with a cross-origin.

this is my code:

  <iframe id="pdf-prueba" name="pdf-box"></iframe>


function open(){
    var pdf = new jsPDF('p', 'mm', [55, 5]);
    var data = pdf.output('datauristring');
    $('#pdf-box').attr("src", data).load(function(){
        document.getElementById('pdf-box').contentWindow.print();
    });
}
+4
source share
1 answer

DOMException: a frame with the source " http: // localhost: 8084 " was blocked from accessing a frame with a transverse beginning.

, , iframe pdf, src datauristring, blob.

:

  • blob pdf (..: pdf.output('blob')..)
  • blob URL (..: URL.createObjectURL(blobPDF))

, (http/data) :

:

document.getElementById('pdf-box')

, , :

document.getElementById('pdf-prueba')

Chrome :

function open(){
  var pdf = new jsPDF('p', 'mm', [55, 5]);

  var blobPDF = pdf.output('blob');

  var blobUrl = URL.createObjectURL(blobPDF);

  $('#pdf-prueba').attr("src", blobUrl).load(function(e){
    document.getElementById('pdf-prueba').contentWindow.print();
  });
}
<iframe id="pdf-prueba" name="pdf-box"></iframe>
+5

Source: https://habr.com/ru/post/1669083/


All Articles