erikzaadi/jQueryPlugins — Issue #35: Printing IFrame sometimes prints page instead of Iframe on IE7 & 8
Author: SteveDonkin
Created: 2012-01-31 09:24:52+00:00
State: open

Seems that sometimes on IE after clearing the cache with the developer tools or having a browser that has never been to the site before - the first time we attempt to print the element (which is a fancybox in a div to give a popup using css) the main page is printed instead of the selected element. My colleague figured out that in some cases the Iframe wasn't created before the print happens. It was quite odd, but seems to be fixed using the onload function which ensures the page is rendered before the printing gets called. It fixed the issue for us. Was a bit of an odd one, but might help others. I wondered if similar issues could be fixed using onload instead of timeout, I didn't fully investigate which browsers would support onload but I think it's been around a while so should have good support.

e.g.
function _callPrint(element) {
if (element && element["printPage"])
// element["printPage"]();

element.onload= function() {
element["printPage"]();
}

else
setTimeout(function () {
_callPrint(element);
}, 50);
}