3

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

Community
  • 1
  • 1
Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97

1 Answers1

2

The following works for me in Firefox 11:

window.frames.loyaltyBadge.focus();
window.frames.loyaltyBadge.print();
Pete
  • 1,554
  • 11
  • 12
  • Really?! 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 May 18 '12 at 14:32
  • I 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 May 18 '12 at 14:33
  • 1
    argh! It does work in isolation! There's obviously something else screwing up my code... I'll start tearing it apart! – Jamie Hartnoll May 18 '12 at 15:07
  • OK, after a bit of fiddling I have worked something out, but not solved the issue. New question here: http://stackoverflow.com/questions/10683066/printing-contents-of-an-iframe-which-has-redirected-to-a-pdf-with-javascript-fir – Jamie Hartnoll May 21 '12 at 09:55
  • 1
    Any version of Firefox since pdf.js was integrated this has stopped working. Best bug I can find on it: https://bugzilla.mozilla.org/show_bug.cgi?id=647658 – Peter Bengtsson May 17 '13 at 23:23
  • In FF17 does not work, displays the following message "Error: Permission denied access to property 'print'" – Bleno Silva Aug 19 '15 at 17:30