a bit of tech and design

Posts Tagged ‘print’

|

printing an invisible iframe

Monday, May 10th, 2010

When I want to let the user print something, and the situation calls for a completely different data layout, my usual solution is to have a print-specific page which I then load in an invisible IFRAME. The print-specific page has a body onload=”window.print();” and everyone’s happy, right?

Wrong. Enter IE to complicate things.

IE prints the entire containing page, instead of just the IFRAME.

After many failed attempts, I’ve discovered the following solution does exactly what I need:

<head>
    <script>
    function printself() {
        try {
            document.execCommand('print', false, null);
        } catch (ex) {
            window.print();
        }
    }
    </script>
</head>
<body onload="printself();">
    /print-specific content here/
</body>

Hope this saves at least one poor soul.

credit: bytes.com/…/629926-ie7-printing-iframe-solution

Tags: , ,
Posted in Uncategorized | No Comments »

|