2

I have followed unlimited examples on how to print an iframe with jQuery, but no matter what I attempt, it doesn't work.

I have a page that has a "Print" button so users can print an iframe. So I followed examples and past experiences with jQuery and came up with this:

$('#printButton').click(function() {        
    window.frames["frameright"].focus();
    window.frames["frameright"].print();
});

Accordingly, my iframe is

<iframe seamless="seamless" id="frameright" name="frameright" src="url..."></iframe> 

but when I click the "Print" button, nothing occurs.

Anyone kind enough to push me in the right direction?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
pattmorter
  • 991
  • 9
  • 21
  • See http://stackoverflow.com/questions/831147/printing-contents-of-a-dynamically-created-iframe-from-parent-window for potential solutions. – Clinton Blackburn Mar 27 '13 at 04:35
  • your code works fine for me for same domain iframe... – Sandeep Mar 27 '13 at 04:37
  • @Sandeep: the src i'm using is not on the same domain. is that the problem? – pattmorter Mar 27 '13 at 04:39
  • yes pattmorter that is the problem. when i tried changing the domain of the iframe its throwing a security exception and not allowing me to open the print dialogue even. – Sandeep Mar 27 '13 at 05:46

1 Answers1

0

No need to use jQuery for this.

Simply use:

function printiframe() {
        window.frames["frameright"].focus();
        window.frames["frameright"].print();
}
jahroy
  • 22,322
  • 9
  • 59
  • 108
abdul
  • 157
  • 5
  • 18