最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Print an iFrame using document.frames in Firefox - Stack Overflow

programmeradmin3浏览0评论

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.

The iFrame (and PDF) is small, so the Adobe Reader navigation is hidden making it impractical to use the Print function within Adobe Reader.

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

print a PDF Iframe in firefox

How to print pdf in iframe using javascript in ie6?

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.loyaltyBadge.print();

Although this works in 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 printFrame and the frame itself has an ID (and name) of loyaltyBadge

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.

The iFrame (and PDF) is small, so the Adobe Reader navigation is hidden making it impractical to use the Print function within Adobe Reader.

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

print a PDF Iframe in firefox

How to print pdf in iframe using javascript in ie6?

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.loyaltyBadge.print();

Although this works in 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 printFrame and the frame itself has an ID (and name) of loyaltyBadge

Share Improve this question edited May 23, 2017 at 10:32 CommunityBot 11 silver badge asked May 18, 2012 at 12:19 Jamie HartnollJamie Hartnoll 7,36114 gold badges63 silver badges100 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

The following works for me in Firefox 11:

window.frames.loyaltyBadge.focus();
window.frames.loyaltyBadge.print();
发布评论

评论列表(0)

  1. 暂无评论