简体   繁体   中英

Firefox printing PDF in an iframe throws an error

Need help

I need to load PDF into iframe while clicking and then call print dialog on it.

I have such code:

$('.print').click(function () {
   var iframe = '<iframe src="test.pdf" id="print-iframe" name="print-iframe"></iframe>';
   $('body').append(iframe);
   window.frames["print-iframe"].focus();
   window.frames["print-iframe"].print();
});

It works perfectly in Chrome. But in Firefox I have such an error: Error: Permission denied to access property 'print' .

How can I work around it? Thanks!

On recent versions of Firefox (since 19), you have to disable the bugged and native PDF viewer (pdf.js) in about:config . Set the pdfjs.disabled property to true and you will see the print window appearing using your script.

If there's a download starting, set the plugin.disable_full_page_plugin_for_types property to application/pdf .

This is error of Src in iframe with full url src="domain.com/file.pdf"

you can try

$('.print').click(function () {

  var domain = location.protocol + "//" + location.host;
  var iframe = '<iframe src="'+domain+'/test.pdf" id="print-iframe" name="print-iframe"></iframe>';
  $('body').append(iframe);
  window.frames["print-iframe"].focus();
  window.frames["print-iframe"].print();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM