Javascript 没有打印对话框的javascript打印

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4292373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:46:49  来源:igfitidea点击:

javascript print without print dialog box

javascript

提问by Bharanikumar

The below snippet working fine, but it opening the dialog box window,

下面的代码片段工作正常,但它打开了对话框窗口,

but i dont want to open the print dialog box ,

但我不想打开打印对话框,

just print should done without dialog box,

只打印应该在没有对话框的情况下完成,

what snippet i should add in the below snippet ,

我应该在下面的片段中添加什么片段,

And also one doubt, i want to take print out in DOT Matrix Printer, the below snippet will work know ?

还有一个疑问,我想在 DOT Matrix Printer 中打印出来,下面的代码片段会起作用吗?

var prtContent = document.getElementById(strid);
var WinPrint =
window.open('','','left=0,top=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;

i developed the billing application ,

我开发了计费应用程序,

If i show the print dialog box, then it consume some seconds to give the print , see i done have more printer, i have only one printer ,that is dot matrix, when ever i give print command , then it should print the BILL without open the print dialog box,

如果我显示打印对话框,那么打印需要几秒钟,看看我有更多的打印机,我只有一台打印机,即点阵,当我给出打印命令时,它应该打印账单而不打开打印对话框,

采纳答案by JoBaxter

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>

回答by user3288769

Download Google Chrome Version 18.xx.xx.xx and you can use flags to turn OFF the printer dialog

下载 Google Chrome 版本 18.xx.xx.xx,您可以使用标志关闭打印机对话框

--kiosk-noprint

--kiosk-noprint

Something of that fashion I can't quite remember off the top of my head but google will help on that. That will allow the dialog to stay out of the way when you select whatever you want to print.

我无法完全记住那种时尚的东西,但谷歌会对此提供帮助。当您选择要打印的任何内容时,这将允许对话框不受影响。

回答by Sandeep

I think the best alternate will be either Flash or Java....

我认为最好的替代方案是 Flash 或 Java ....

Flash is very flexible in terms of customizing the OS elements....

Flash 在自定义操作系统元素方面非常灵活......

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/printing/PrintJob.html

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/printing/PrintJob.html

So, user can define Printers through he want to print and you can just pass the name of the printer to the function and that printer will start printing.....

因此,用户可以通过他想要打印的方式定义打印机,您只需将打印机的名称传递给函数,该打印机就会开始打印.....

回答by thejh

It's not possible, and there are a few good reasons for that:

这是不可能的,有几个很好的理由:

  • the user could want to choose a printer himself
  • the user could want to be able to control when his printer gets activated (imagine nasty auto-selfprinting advertisement popups, ARRGH!)
  • the user could want to specify printer settings (grayscale or color, resolution, size, ...)
  • 用户可能想要自己选择打印机
  • 用户可能希望能够控制他的打印机何时被激活(想象一下讨厌的自动打印广告弹出窗口,ARRGH!
  • 用户可能想要指定打印机设置(灰度或颜色、分辨率、尺寸……)