Print an iFrame using document.frames in Firefox
The following works for me in Firefox 11:
window.frames.loyaltyBadge.focus();
window.frames.loyaltyBadge.print();
Jamie Hartnoll
Updated on June 05, 2022Comments
-
Jamie Hartnoll almost 2 years
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.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) ofloyaltyBadge
-
Jamie Hartnoll almost 12 yearsReally?! That's strange, it just won't do anything for me. I'm on FF 12, but I don't see why that should have stopped it!!
-
Jamie Hartnoll almost 12 yearsI have checked the click event is being captured OK, by adding an alert in there too, that works but then nothing else happens.
-
Jamie Hartnoll almost 12 yearsargh! It does work in isolation! There's obviously something else screwing up my code... I'll start tearing it apart!
-
Jamie Hartnoll almost 12 yearsOK, after a bit of fiddling I have worked something out, but not solved the issue. New question here: stackoverflow.com/questions/10683066/…
-
Peter Bengtsson almost 11 yearsAny version of Firefox since pdf.js was integrated this has stopped working. Best bug I can find on it: bugzilla.mozilla.org/show_bug.cgi?id=647658
-
Bleno Silva over 8 yearsIn FF17 does not work, displays the following message "Error: Permission denied access to property 'print'"