【问题标题】:Trying to print pdf through iframe, get error in Firefox尝试通过 iframe 打印 pdf,在 Firefox 中出现错误
【发布时间】:2014-08-06 21:11:08
【问题描述】:

在 Chrome 中它工作正常,但在 Firefox 中我收到此错误:

Error: Permission denied to access property 'print'

我的代码:

<iframe src="http://domain.com/wp-content/uploads/2014/08/CV.pdf" id="PDFtoPrint"></iframe>
<a class="" href="#" title="Print CV" onclick="document.getElementById('PDFtoPrint').focus();document.getElementById('PDFtoPrint').contentWindow.print();"></a>

我在firefox forum 上看到了这个错误。它解决了吗?

还有其他解决方案吗?

谢谢!

编辑:在 IE 上我收到此错误:

SCRIPT65535: Invalid calling object

【问题讨论】:

  • @ThomasWTupper 来自iframe 的文档位于同一网站上。我把它放在同一个文件夹中。我尝试使用http://http://www. 并得到同样的错误。根据您的链接,它应该可以工作,对吧?
  • 这几乎可以肯定是一个安全例外。但是您是否尝试过这里的方法:stackoverflow.com/questions/9616426/…
  • @ThomasWTupper 好的,那个正在工作。谢谢!
  • 小心——我没有彻底检查它,但在我看来这是脆弱的,并不适用于所有浏览器。彻底测试。

标签: javascript firefox iframe printing


【解决方案1】:

像这样解决它:

<script>
    function for_print(){
      window.frames["printf"].focus();
      window.frames["printf"].print();
      var newWin = window.frames['printf'];
    }
</script>

<iframe style="display:none;" id="printf" name="printf" src="demo.html"></iframe>
<iframe src="demo.html" id="PDFtoPrint" style="display:none;"></iframe>

【讨论】:

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