javascript 在 Firefox 中使用 document.frames 打印 iFrame

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10652525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:33:50  来源:igfitidea点击:

Print an iFrame using document.frames in Firefox

javascriptjquerypdfiframeprinting

提问by Jamie Hartnoll

This is driving me crazy.

这真让我抓狂。

I've been through several questions on here and other websites and cannot get this to work.

我已经在这里和其他网站上解决了几个问题,但无法解决这个问题。

I have an iFrame within my parent page, containing a PDF document.

我的父页面中有一个 iFrame,其中包含一个 PDF 文档。

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(和 PDF)很小,因此 Adob​​e Reader 导航是隐藏的,因此在 Adob​​e Reader 中使用打印功能是不切实际的。

So, I want a button (which has to be in the Parent frame) which can trigger Printon the iFrame window.

所以,我想要一个可以Print在 iFrame 窗口上触发的按钮(必须在父框架中)。

print a PDF Iframe in firefox

在 Firefox 中打印 PDF iframe

How to print pdf in iframe using javascript in ie6?

如何在 ie6 中使用 javascript 在 iframe 中打印 pdf?

and a few other have similar suggestions.

和其他一些人也有类似的建议。

Using Firefox

使用火狐

document.getElementById('loyaltyBadge').focus();
document.getElementById('loyaltyBadge').contentWindow.print();

Does nothing

什么也没做

document.frames['loyaltyBadge'].focus();
document.frames['loyaltyBadge'].contentWindow.print();

Does nothing

什么也没做

document.frames.loyaltyBadge.focus();
document.frames.loyaltyBadge.contentWindow.print();

Returns document.frames is undefined... as does:

返回document.frames is undefined... 一样:

document.loyaltyBadge.print();

Although this works in Chrome

虽然这适用于 Chrome

I don't want to auto-print on load, but I need a print button.

我不想在加载时自动打印,但我需要一个打印按钮。

All the lines above are being wrapped in:

上面的所有行都被包裹在:

$('#printFrame').click(function () {  });

The button having an id of printFrameand the frame itself has an ID (and name) of loyaltyBadge

具有 id 的按钮printFrame和框架本身具有的 ID(和名称)loyaltyBadge

回答by Pete

The following works for me in Firefox 11:

以下在 Firefox 11 中对我有用:

window.frames.loyaltyBadge.focus();
window.frames.loyaltyBadge.print();