Jack
Jack

Reputation: 9784

JavaScript: When printing a full web page, IE doesn't seem to print the contents of iFrames on the page

The client's website has product listings. The prices for the product are pulled dynamically in through an iFrame at the bottom of the page. There is Javascript on the page that automatically resizes this iFrame to the correct height based upon how big the iFrame content is, once it's loaded.

The client is reporting that when printing the page, they cannot see anything from the iFrame where the prices should be - apparently it is not printing in IE, just the main page itself.

I am on a Mac and so can't test in IE, so I'm having a hard time experimenting with this.

Can anyone clarify the expected behaviour in this situation? Is it possible to get IE to print both page and included iFrames by default, and if so, how would I go about doing this? I can only find examples for printing a specific frame from a parent window.

Thanks!

Upvotes: 8

Views: 3725

Answers (5)

Zeshan
Zeshan

Reputation: 75

Try this Plugin it will solved your problem http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/

Upvotes: 0

JoDev
JoDev

Reputation: 6873

I can't explain why IE isn't working, but maybe you can fix the problem by adding this part of code into the parent page, in order to force each iframe to be refresh :

$(document).ready(function() {
    if($.browser.msie) {//Only for IE
        $('iframe').each(function() {
          $(this).attr('src', $(this).attr('src'));
        });
     }
});

To get the browser, i use this method.
And i don't use contentDocument.location.reload(true); method to be sure the iframe to be refresh. See SO topic.

Upvotes: 0

Chase
Chase

Reputation: 29549

The expected behaviour should be what you're experiencing in other browsers. If the page is printed, the iframe should be printed along with it. It would be difficult to imagine that everyone else got it wrong and IE got it correct in this instance.

Below is a bit of speculation on what the issue might be, but without knowing more/seeing code it's difficult to know the specifics:

This issue could be due to some css that you may have on your page. I've read of similar iframe printing issues where the visibility was set to hidden initially resulting in the iframe not printing correctly. To get around this specific case the user had to set the width and height to 0px. Without knowing more about your site, I can not correctly predict that this is happening.

Another issue may by your dynamic resizing based on the contents of the iframe. A simple test would be to comment that section out and set a generic width and height on the iframe to see if the printing issue still occurs. Perhaps those dynamic styles are not being carried over to the print stylesheet and are not getting applied (therefore not appearing at all).

As a quick suggestion, look into css media types:

print

Intended for paged material and for documents viewed on screen in print preview mode. Please consult the section on paged media for information about formatting issues that are specific to paged media.

Helpful link: Print Specification

Upvotes: 1

Sanjeev Rai
Sanjeev Rai

Reputation: 6972

If you are using Javascript, then why not try window.print() function along with print media CSS.

Upvotes: 0

Shazboticus S Shazbot
Shazboticus S Shazbot

Reputation: 1289

This was an interesting point, so I did a test using IE8 (on a server, not locally).

I printed in IE8 a web page that included an iframe of something that I built. And it printed some of the contents the first time (the other contents showed up black). The second time I printed, the iframe contents were all black.

However, in my example, the contents in the iframe are changing constantly (images and text that fade in and out) and the css background behind it is black.

This test has the contents of the iFrame on a different host server than the contents of the main page. But to my knowledge, there is a cross-domain policy file working here.

Cross-domain policy issues were my first guess, but it's entirely possible there is some issue with how internet explorer renders the screenshot when it sends it to the printer.

Upvotes: 0

Related Questions