javascript - 如何在 Opera 中使用 javascript 打印 PDF 文件?

标签 javascript pdf printing

我可以使用 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 中,打印功能不起作用。

如何让它发挥作用?

谢谢。

最佳答案

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

window.print not working with opera browser

print() not working on opera browser

Print iframe content in Opera and Chrome

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

希望这些链接有所帮助。

关于javascript - 如何在 Opera 中使用 javascript 打印 PDF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6130110/

相关文章:

javascript - 如何添加名称并将数组值转换为 JSON?

javascript - angular2中templatURL中的动态模板

python - 是否可以在 PyQt 应用程序中预览 pdf?

java - 如何在 Java 中将 .docx 文件转换为 .pdf

windows - Win32 终端 : unexpected printing behavior

c# - 捆绑 css 文件 - 找不到文件

javascript - 无法运行代码

java - 如何在 iText 7 中创建/设置表格单元格和边框的自定义颜色?

javascript - 打印 JSON 解析的对象?

Python 3.7.1 try except block 在命令行中以错误的顺序发生