Keywords: IE, iframes, printing
First I should admit that I don’t think of myself primarily as a frontend web developer. I’ve always thought of myself as an enterprise architect first, and a backend programmer second. I have no stake in the debates over liquid design versus tables, or over the inherent evilness of frames and iframes. But sometimes, like today, I have to wade right in. Briefly, I have a web application which allows users to build an HTML report from various dynamically generated ASP.Net forms, and users have the ability to upload attachments to the report. The attachments are primarily Microsoft Office documents with a few JPEGS and plain text thrown in.
So naturally the users want everything to display inline and print from a single button.
Implementing this solution is easy using iframes. Here is a sketch for a sample report with two attachments. (In the following, ServeFile.ashx is n ASP.Net web handler that serves files, but you could replace it with whatever URL suits you on your domain.)
</iframe> instead of making it an empty tag on purpose. Necessary and truly goofy. See also this page.)
So what do you get when you display this page in IE6 and click the “Print All” button? I got a few print dialogs to which I answered “Print”, I got the “H! I’m a report!” page, and I got the contents of the second iframe, iframe #2, twice. Nothing from iframe #1. Interesting.
It took an hour and a ream of paper, but it turns out that the problem is that the iframe you want to print has to be in focus when you hit the print button on the print dialog. (90% of the forums I sampled that suggested something along the lines of the above stopped at one iframe. Hmmmm.) It turns out that the following solution does work:
Of course, this solution is silly, like a poor Dickensian cobbler using one shoe to pound nails into the sole of another shoe. So I ended up including good old empty hyperlinks to content alongside iframes displaying the same content, and I ask my users to check the “Print All Linked Documents” option in their print dialog options tab. I think this may only be an option in IE6, unfortunately.
By the way, this why I’m not a frontend developer.