[英]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. 我需要在单击时将PDF加载到
iframe
,然后在其上调用打印对话框。
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. 它在Chrome中完美运行。 But in Firefox I have such an error:
Error: Permission denied to access property 'print'
. 但是在Firefox中,我遇到这样的错误:
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
. 在Firefox的最新版本(自19开始)上,您必须在
about:config
禁用错误的本机PDF查看器(pdf.js)。 Set the pdfjs.disabled
property to true
and you will see the print window appearing using your script. 将
pdfjs.disabled
属性设置为true
,您将看到使用脚本显示的打印窗口。
If there's a download starting, set the plugin.disable_full_page_plugin_for_types
property to application/pdf
. 如果下载开始,请将
plugin.disable_full_page_plugin_for_types
属性设置为application/pdf
。
This is error of Src in iframe with full url src="domain.com/file.pdf" 这是iframe中具有完整网址src =“ domain.com/file.pdf”的Src错误
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();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.