在Firefox中使用document.frames打印iFrame [英] Print an iFrame using document.frames in Firefox
问题描述
这让我发疯了。
我在这里和其他网站上遇到过几个问题而无法让它发挥作用。
I've been through several questions on here and other websites and cannot get this to work.
我的父页面中有一个包含PDF文档的iFrame。
I have an iFrame within my parent page, containing a PDF document.
iFrame(和PDF)很小,因此Adobe Reader导航被隐藏,因此在Adobe Reader中使用打印功能是不切实际的。
The iFrame (and PDF) is small, so the Adobe Reader navigation is hidden making it impractical to use the Print function within Adobe Reader.
所以,我想要一个按钮(必须在父框架中),它可以触发在iFrame窗口打印
。
So, I want a button (which has to be in the Parent frame) which can trigger Print
on the iFrame window.
如何在ie6中使用javascript在iframe中打印pdf?
和其他一些人有类似的建议。
and a few other have similar suggestions.
使用 Firefox
document.getElementById('loyaltyBadge').focus();
document.getElementById('loyaltyBadge').contentWindow.print();
什么都不做
document.frames['loyaltyBadge'].focus();
document.frames['loyaltyBadge'].contentWindow.print();
什么都不做
document.frames.loyaltyBadge.focus();
document.frames.loyaltyBadge.contentWindow.print();
返回 document.frames未定义
.. 。as as:
Returns document.frames is undefined
... as does:
document.loyaltyBadge.print();
虽然这适用于 Chrome
我不想在加载时自动打印,但我需要一个打印按钮。
I don't want to auto-print on load, but I need a print button.
以上所有行正在包装:
$('#printFrame').click(function () { });
ID为 printFrame
的按钮框架本身的ID(和名称)为 loyaltyBadge
The button having an id of printFrame
and the frame itself has an ID (and name) of loyaltyBadge
推荐答案
以下适用于Firefox 11:
The following works for me in Firefox 11:
window.frames.loyaltyBadge.focus();
window.frames.loyaltyBadge.print();
这篇关于在Firefox中使用document.frames打印iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!