Print an iFrame using document.frames in Firefox

14,801

The following works for me in Firefox 11:

window.frames.loyaltyBadge.focus();
window.frames.loyaltyBadge.print();
Share:
14,801
Jamie Hartnoll
Author by

Jamie Hartnoll

Updated on June 05, 2022

Comments

  • Jamie Hartnoll
    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.

    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

  • Jamie Hartnoll
    Jamie Hartnoll almost 12 years
    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
    Jamie Hartnoll almost 12 years
    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
    Jamie Hartnoll almost 12 years
    argh! It does work in isolation! There's obviously something else screwing up my code... I'll start tearing it apart!
  • Jamie Hartnoll
    Jamie Hartnoll almost 12 years
    OK, after a bit of fiddling I have worked something out, but not solved the issue. New question here: stackoverflow.com/questions/10683066/…
  • Peter Bengtsson
    Peter Bengtsson almost 11 years
    Any 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
    Bleno Silva over 8 years
    In FF17 does not work, displays the following message "Error: Permission denied access to property 'print'"