Help with JScript printing code

Associate
Joined
26 Jul 2003
Posts
1,352
Location
Loughborough
I need to make an asp page output to the printer on completion without using any of the dialogue buttons that you would normally use when printing from IE. Google turned up the code below which allegedly achieves this but the code will not run in my browser without generating errors. It seems to want a semi colon after the word FUNCTION on line 13 before the name of the function being described.

I have a good knowledge of ASP but Java has me stumped. Can anybody work out why the script fails or give me a better method for causing the browser to print after the page has loaded?

<HTML>
<BODY onload="Print()">
<object id="WBControl" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>

<script language="VBScript"><!--
Sub VBPrint() On Error Resume next
WBControl.ExecWB 6,1
End Sub
//--></script>

<script language=JavaScript><!--

Function Print()
{
if(self.print)
{
self.print();
self.close();
return False;
}
else if (navigator.appName.indexOf(' Microsoft') != -1)
{
VBPrint();
self.close();
}
else
{
alert("To print this document, you will need to\nclick the Right Mouse Button and select\n' Print'");
}
}
//-->
</script>
<P>
Me<br>
<p>
<h1>This page will now show the print dialog</h1>
... please wait
</BODY>
</HTML>


Thanks in advance chaps.
 
Basically if it's through a web page I don't think you can? Don't use anything with client-side VBScript as it'll not work in any browser except IE which is bad.

Normally in JavaScript (not Java, different language) you'd do window.print(). I guess you could do <body onload="window.print();"> ? This would open the print dialogue as soon as the page finished loading but I don't think you can bypass that as it allows people to choose their printer etc which I don't think you'd want to bypass?
 
Back
Top Bottom