javascript Firefox 在 iframe 中打印 PDF 会引发错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15769933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:02:57  来源:igfitidea点击:

Firefox printing PDF in an iframe throws an error

javascriptfirefoxprinting

提问by Kosmetika

Need help

需要帮忙

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

我需要iframe在单击时将 PDF 加载到其中,然后在其上调用打印对话框。

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'.

它在 Chrome 中完美运行。但是在 Firefox 中我有这样的错误: Error: Permission denied to access property 'print'.

How can I work around it? Thanks!

我该如何解决?谢谢!

回答by Epoc

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.disabledproperty to trueand you will see the print window appearing using your script.

在最新版本的 Firefox 上(自 19 起),您必须在about:config. 将该pdfjs.disabled属性设置为true,您将看到使用您的脚本出现的打印窗口。

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

如果开始下载,请将plugin.disable_full_page_plugin_for_types属性设置为application/pdf

回答by khoa vo

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

这是 iframe 中 Src 的错误,带有完整的 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();
});