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
Firefox printing PDF in an iframe throws an error
提问by Kosmetika
Need help
需要帮忙
I need to load PDF into iframe
while 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.disabled
property to true
and 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_types
property 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();
});