【问题标题】:How do I print a PDF file using javascript in Opera?如何在 Opera 中使用 javascript 打印 PDF 文件?
【发布时间】:2011-05-25 19:56:35
【问题描述】:

我可以使用 javascript 在 Internet Explorer 和 Firefox 中打印 PDF 文件,例如:

<script type="text/javascript">
<!--
if (navigator.appName == 'Microsoft Internet Explorer')
{
    document.write('<object id="agreementPDF" type="application/pdf" data="file.pdf" width="100%" height="500"></object>');
}
else
{
    document.write('<iframe id="agreementFrame" src="file.pdf" width="100%" height="500px"></iframe>');
}
//-->
</script>

<script type="text/javascript">
<!--
function printAgreement()
{
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        document.getElementById('agreementPDF').print();
    }
    else
    {
        var agreement = document.getElementById('agreementFrame');
        agreement.focus();
        agreement.contentWindow.print();
    }   
}
//-->
</script>

<input type="button" name="print" onclick="printAgreement();" value="Print" />

但是,在 Opera 中,打印功能不起作用。

如何让它发挥作用?

谢谢。

【问题讨论】:

    标签: javascript pdf printing


    【解决方案1】:

    在打印对话框方面,Opera 似乎需要更多的帮助。以下是之前在堆栈overflow上提出/回答的一些非常相似的问题:

    window.print not working with opera browser

    print() not working on opera browser

    Print iframe content in Opera and Chrome

    似乎您要么需要使用不同的 *.print() 函数,要么在页面加载完成后触发事件。

    希望这些链接有所帮助。

    【讨论】:

      【解决方案2】:

      您是否尝试过在窗口的 onload 事件上打印?

      window.onload = function(){
        window.print();
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-05
        • 2013-03-19
        • 2011-11-03
        • 1970-01-01
        • 1970-01-01
        • 2011-11-21
        • 2013-02-16
        • 2014-07-05
        相关资源
        最近更新 更多