【问题标题】:Firefox printing PDF in an iframe throws an errorFirefox 在 iframe 中打印 PDF 会引发错误
【发布时间】:2013-04-02 17:00:07
【问题描述】:

需要帮助

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

我有这样的代码:

$('.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();
});

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

我该如何解决?谢谢!

【问题讨论】:

    标签: javascript firefox printing


    【解决方案1】:

    在最新版本的 Firefox(自 19 起)上,您必须禁用 about:config 中的错误和原生 PDF 查看器 (pdf.js)。将pdfjs.disabled 属性设置为true,您将看到使用您的脚本出现的打印窗口。

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

    【讨论】:

    • 这对我有用,但对我来说最终的解决方案是将 compatability.js 更新到较新的版本
    【解决方案2】:

    这是带有完整 url src="domain.com/file.pdf" 的 iframe 中的 Src 错误

    你可以试试

    $('.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();
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 2014-10-19
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多