Search code examples
iframeprintinginternet-explorer-6srcprinting-web-page

Fake the src of an iframe for printing to avoid "about:blank"


I'm creating a hidden iframe specifically to be used for printing in IE6.

Here's a basic outline of the code with some HTML population cut out:

$('body').append('<iframe id="printIFrame"></iframe>');

$("iframe#printIFrame").attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');

$("iframe#printIFrame").load(function()
{
    document.getElementById("printIFrame").contentWindow.document.title = "My Title";

    var iframe = document.getElementById("printIFrame");
    iframe.contentWindow.focus();
    iframe.contentWindow.print();

    $("iframe#printIFrame").remove();
});

This is working quite well, except for the ugly "about:blank" that shows at the bottom left hand of each printed page. I guess since I'm making this iframe on the fly the source (as IE6 sees it) is about:blank. Is there any way to fake the src or change what gets printed there? I tried setting the src right before printing, but obviously that changes the iframe to a new page and prints that. Any ideas?


Solution

  • I did find an ActiveX plugin which claims you can modify the header/footer of the printout on the fly.

    http://www.meadroid.com/sx_intro.asp

    Alternatively, it can be changed permanently by going to Page Setup from the File menu in IE6. However I'm trying to avoid an ActiveX plugin if possible; I'm wondering if there is an easy way to change the header or footer through javascript. Any other ideas?