Friday, May 28, 2004

Print from a web page without a dialog box

This is bad practice, as far as I'm concerned. Sometimes you just have to do what you have to do though.

You may be required to tweak your browser security settings to allow ActiveX downloads to get it completely transparent, so tread carefully.

<html>
<head>
<title>Title of your print test page.</title>
<script>
function Print()
{
if (document.all)
{
WebBrowser1.ExecWB(6, 6) //use 6, 1 to prompt the print dialog or 6, 6 to omit it;
WebBrowser1.outerHTML = "";
}
else
{
window.print();
}
}
</script>

</head>
<body>

<div style="page-break-before:always">
<p>This would be your page text.</p>


<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>

<SCRIPT>
<!--
Print()
//-->
</SCRIPT>

</div>

</body>
</html>

No comments:

Post a Comment