Wednesday, October 31, 2007

Print Page from IE without Prompt 

This code should send a page straight to the printer without prompting the user. It worked in IE6, but I don't know about IE7. I am sure there are some security concerns with it.


<html>
<head>
<script language="javascript">
    function ieExecWB(intOLEcmd, intOLEparam)
    {
        var WebBrowser = '<OBJECT ID="PrintBrowser" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || ( intOLEparam > 1 ) )
        { 
            intOLEparam = 1;
        }
        PrintBrowser.ExecWB(intOLEcmd, intOLEparam);
        PrintBrowser.outerHTML = "";
    }
</script>
</head>
<body>

<p><a href="javascript:ieExecWB(6, -1);">print</a></p>

</body>
</html>

NOTE: I don't know where I found this code so if someone needs attribution or it violates a copyright or something, let me know.

This page is powered by Blogger. Isn't yours?