Google Chrome - PDF loading in iFrame does not work

So, due to a recent Chrome update preventing a direct url using javaScript: "It is not allowed to navigate to the top frame with the data url", I have a code that I need to change. I have an ajax call that uses mPDF to create a PDF file, sends it back to base 64 and should open in a new tab. It always worked. However, due to this problem, what I'm trying to do now is upload this PDF file to iFrame in a new window to avoid the error. And it works, here is what I have:

$('.print-order-pdf').click(function(){

    var orderNumber = $(this).attr('order')
    var data = {
        pdfnonce: pdfAjax.pdfnonce,  
        action: 'getOrderPDF',
        orderNumber: orderNumber,
    }
    var win = window.open('', '_blank');
    $.post(pdfAjax.ajax_url, data, function(return_url){           
        win.document.write("<iframe id='pdf' src='"+ return_url +"'></iframe>");
        win.document.write("<style> html, body{ overflow:hidden; margin:0; } #pdf{ width:100%; height: 100%; }</style>");
    });

});

( Ajax wordPress). - PDF. , Chrome , PDF, . , , , . firefox, . Chrome PDF . ? - Chrome, iFrame? ? ?

.

+4
1

! chrome 61.0.3163.100. , , google. , , chrome PDF.

, , . :

var newWindow = window.open("", "PDF", 'dependent=yes,locationbar=no,scrollbars=no,menubar=no,resizable,screenX=50,screenY=50,width=850,height=800');
newWindow.document.write(
'<html><body><center>' +
'<a title="Download File" style="font-family: \'Verdana\';color: #333;text-decoration: none;font-weight: 600;" download="File.PDF" href="data:application/pdf;base64,' + base64 + '">Download File</a>' +
'</center><br>' +
'<object width=100% height=100% type="application/pdf" data="data:application/pdf;base64,' + base64  + '">' +
'<embed type="application/pdf" src="data:application/pdf;base64,' + base64  + '" id="embed_pdf"></embed>' +
 '</object></body></html>');
 newWindow.window.focus();
+1

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


All Articles