且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript打印没有打印对话框

更新时间:2023-09-12 18:11:16

这是完全可能的。我在银行工作,并有一个网页,计票员需要在发布交易时自动打印。由于他们整天进行交易,如果他们每次都显示对话框,就会减慢它们的速度。此代码将选择您的默认打印机并直接打印到它,没有对话框。

This is totally possiable. I work in banking and had a webpage that tellers needed to auto print when a transaction was posted. Since they do transactions all day it would slow them down if they had the dialog box display everytime. This code will select your default printer and print directly to it with no dialog box.

<form>
<input type="button" value="Print Page" onClick="window.print()">
</form>


<script language="VBScript">
// THIS VB SCRIP REMOVES THE PRINT DIALOG BOX AND PRINTS TO YOUR DEFAULT PRINTER
Sub window_onunload()
On Error Resume Next
Set WB = nothing
On Error Goto 0
End Sub

Sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1


On Error Resume Next

If DA Then
call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)

Else
call WB.IOleCommandTarget.Exec(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","","")

End If

If Err.Number <> 0 Then
If DA Then 
Alert("Nothing Printed :" & err.number & " : " & err.description)
Else
HandleError()
End if
End If
On Error Goto 0
End Sub

If DA Then
wbvers="8856F961-340A-11D0-A96B-00C04FD705A2"
Else
wbvers="EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B"
End If

document.write "<object ID=""WB"" WIDTH=0 HEIGHT=0 CLASSID=""CLSID:"
document.write wbvers & """> </object>"
</script>