364,085 Members | 5261 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

IE7 Printing Iframe Solution

arielzriel
P: 1
Dear All,

I was looking for a solution to print Iframes in Internet Explorer 7 (IE7)

the command window.print() ( even with window.focus) in an iframe does not work.

The solution is
<script language=javascipt>

document.execCommand('print', false, null);

</script>

I spent alot wasted time figuring this out, hope it helps!

best regards,

Ariel

I am considering making Goofi.com free, any ideas on a revenue model?
Goofi is a Live Chat for website with Audio and Video to comunicate with consumers before a sale.
Apr 9 '07 #1
Share this Question
Share on Google+
4 Replies


amalbet
P: 1
You are the man!! It works!!
Jan 2 '08 #2

q1712
P: 2
used it this way:
Expand|Select|Wrap|Line Numbers
  1.         <script type="text/javascript">
  2.             try
  3.             {
  4.                 document.execCommand('print', false, null);
  5.             }
  6.             catch(e)
  7.             {
  8.                 window.print();
  9.             }
  10.         </script>
  11.  
works perfectly, thanks.
Jun 26 '09 #3

Leif Meyer
P: 1
I am in your debt.

Also, I think this might clarify q1712's example if your code executed from the window containing the iframe, as mine is:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.             try
  3.             {
  4.                 iframe = document.getElementById('iframe-id');
  5.                 iframe.contentWindow.document.execCommand('print', false, null);
  6.             }
  7.             catch(e)
  8.             {
  9.                 window.print();
  10.             }
  11. </script>
Sep 25 '10 #4

q1712
P: 2
i got an email when leif send his reply.

he was a PRO using the information the righ way (thx 4 converting it to a parent-frame-script)

anway, there is still an issue i solved, that may be of intrest:

one vession of the windoof-browser (IE7) was not able (able but not willing) to print anything that wasn't rendet.

that means: i always got the printer to print, but sometimes it was an emty page.

so: use this script as an "onload-funtion" put it at the end of the "<body>-tag" or just give it a timeout.

i'd like to post the the script, but i was 2able2 keep my job, and i'll never ever steal code form my former employ.
Sep 30 '10 #5

Post your reply

Help answer this question



Didn't find the answer to your Misc question?

You can also browse similar questions: Misc print iframe printing iframe