By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,583 Members | 1,084 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,583 IT Pros & Developers. It's quick & easy.

IE7 Printing Iframe Solution

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);


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

best regards,


I am considering making 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+
6 Replies

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

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>
works perfectly, thanks.
Jun 26 '09 #3

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

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

P: 1
Thank you for saving me time. May i add this is the only code that will print full frame in IE8 and IE9.

parent.framename.print(); does not work.
window.print(); does not work.

The above only prints a portion of the visible frame, if you have scrolling it does not print the rest of the page.

Here is my print frame solution based on your code

In head:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function printfrm() {
  3.         document.execCommand('print', false, null);
  4.     }
  5. </script>
Then in the body:

Expand|Select|Wrap|Line Numbers
  1. <input type="button" value="Print this page" onClick="printfrm();" />
Aug 30 '12 #6

P: 1
what if we have more than 1 iframe in a can i print all the content of iframe without truncating.
Sep 9 '14 #7

Post your reply

Sign in to post your reply or Sign up for a free account.