[英]How do I print a PDF file using javascript in Opera?
我可以使用 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 中,打印 function 不起作用。
我如何使它工作?
謝謝。
看起來 Opera 在打印對話框時需要更多的手。 以下是之前在堆棧溢出中提出/回答的一些非常相似的問題:
在 Opera 和 Chrome 中打印 iframe 內容
似乎您需要使用不同的 *.print() function 或在頁面完成加載后觸發事件。
希望這些鏈接有所幫助。
您是否嘗試過在窗口的 onload 事件上打印?
window.onload = function(){
window.print();
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.