So due to the recent Chrome update preventing a data URL from being opened directly using javaScript: "Not allowed to navigate top frame to data URL", I have some code that I need to modify. I have an ajax call that uses mPDF to generate a PDF, sends it back base 64 - and should open in a new tab. This always worked. However due to this issue, what I'm now trying to do is load that PDF into an iFrame in a new window to avoid the error. And that works, here's 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>");
});
});
(This is a wordPress Ajax call). In any case - it all works and the new page with PDF opens. The problem is - in Chrome, the download link that appears as part of the PDF controls no longer works. I can print, rotate, whatever - but not download the file. I've tested in firefox, no issue triggering the download there. The Chrome console for the PDF window shows no errors at all. Any ideas? Is there something specific in Chrome preventing the download from inside the iFrame? Why? Is there a way around it?
Thanks so much in advance.