|
The Macintosh version of Internet Explorer does not support VBScript. It generates an error dialog box if it encounters such a script. You must use JavaScript to print the VBScript code. The following VBScript function is responsible for printing a Web page:
<SCRIPT LANGUAGE="VBScript">
<!--
Sub window_onunload
On Error Resume Next
Set WB = nothing
End Sub
Sub vbPrintPage
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
On Error Resume Next
WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End Sub
// -->
</SCRIPT>
We must use JavaScript to overcome the Macintosh issue:
<SCRIPT LANGUAGE="JavaScript">
<!--
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);
function printPage() {
if (pr) // NS4, IE5
window.print()
else if (da && !mac) // IE4 (Windows)
vbPrintPage()
else // other browsers
alert("Sorry, your browser doesn't support this feature.");
return false;
}
if (da && !pr && !mac) with (document) {
writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
writeln('Sub window_onunload');
writeln(' On Error Resume Next');
writeln(' Set WB = nothing');
writeln('End Sub');
writeln('Sub vbPrintPage');
writeln(' OLECMDID_PRINT = 6');
writeln(' OLECMDEXECOPT_DONTPROMPTUSER = 2');
writeln(' OLECMDEXECOPT_PROMPTUSER = 1');
writeln(' On Error Resume Next');
writeln(' WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
writeln('End Sub');
writeln('<' + '/SCRIPT>');
}
// -->
</SCRIPT>
<A HREF="#" onClick="return printPage()">Print</A>
Notice the use of the navigator.userAgent property to check if the user is running a Mac.
People who read this tip also read these tips:
Look for similar tips by subject:
|