首先在HTML 頁面中加入WebBrowser 的Object:
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
之后,使用如下代碼進行打?。?/P>
<script language="VBScript">
sub printvb()
wb.execwb 6,2,3
End Sub
</script>
關(guān)鍵代碼 wb.execwb 6,2,3 可以在 VBScript 方式下實際無需提示的直接打印,但奇怪的是用同樣的參數(shù),在 Javascript 方式下IE 依然會彈出打印對話窗口,也許是因為VBScript 是Microsoft 開發(fā)的專用于 IE 的吧,而 Javascript 畢竟是外人:)
另找到一個較全面的例子,如下:
6=OLECMDID_PRINT
2=OLECMDEXECOPT_DONTPROMPTUSER,
2+1=PRINT_WAITFORCOMPLETION + PRINT_DONTBOTHERUSER
WB.ExecWB 6, 2, 3, 0
<HTML>
<HEAD>
<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>
<SCRIPT LANGUAGE="VBScript">
Sub window_onunload
On Error Resume Next
Set WB = nothing
End Sub
Sub vbPrintPage ( x , y , z )
OLECMDID_PRINT = 6
OLECMDEXECOPT_DODEFAULT = 0
OLECMDEXECOPT_PROMPTUSER = 1
OLECMDEXECOPT_DONTPROMPTUSER = 2
On Error Resume Next
WB.ExecWB x, y, z, 0
End Sub
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER=1><TR><TD>
<INPUT TYPE="BUTTON" VALUE="Print" ONCLICK="vbPrintPage 6, 2, 3"><BR>
<INPUT TYPE="BUTTON" VALUE="Preview" ONCLICK="vbPrintPage 7, 1, 0"><BR>
<INPUT TYPE="BUTTON" VALUE="Page Setup" ONCLICK="vbPrintPage 8, 1, 0"><BR>
</TD>
<TD bgcolor="green">Print Test
</TD></TR></TABLE>
</BODY>
</HTML>