简体   繁体   English

javascript打印没有打印对话框

[英]javascript print without print dialog box

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矩阵打印机中打印出来,下面的代码片段会知道吗?

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, 如果我显示打印对话框,那么它会花费几秒钟来打印,看到我完成了更多打印机,我只有一台打印机,即点阵,当我给出打印命令时,它应该打印出没有打开打印对话框,

It seems most people focused on the negative aspects of such a feature. 似乎大多数人都关注这种功能的消极方面。

Yes, in most cases it would not be desirable that a website could suppress the dialog box. 是的,在大多数情况下,网站可能无法取消对话框。

But in a few cases, such as this example where he's trying to print a receipt for his business from the browser. 但在少数情况下,比如这个例子,他试图从浏览器打印他的业务收据。 As I understand in such a case every second is too precious to be wasted confirming potentially hundreds of receipt per day. 据我所知,在这种情况下,每一秒都太宝贵,无法浪费,确认每天可能有数百张收据。

It's a business after all, where time is money! 毕竟这是一项业务,时间就是金钱!

There are countless other cases where one would like to suppress the dialog box, such as the eBay sellers printing their labels before shipment. 有无数其他情况下,人们想要取消对话框,例如eBay卖家在发货前打印他们的标签。

So ideally the website developer should be able to specify some basic parameters such as printer name, color/monochromatic, quality, paper size. 理想情况下,网站开发人员应该能够指定一些基本参数,如打印机名称,颜色/单色,质量,纸张大小。 And command the print entirely from the source coude without requiring any action from the user, except of course to configure these parameter only once. 并且完全从源代码命令打印而不需要用户的任何操作,除了当然只配置这些参数一次。

Unfortunately most browsers aren't there yet, as their developers haven't waken yet to the full potential of hosting ALL KINDS of applications on the cloud, including applications that use printers such as POS and label printing software! 不幸的是,大多数浏览器还没有,因为他们的开发人员尚未充分发挥在云上托管所有应用程序的潜力,包括使用POS和标签打印软件等打印机的应用程序! By the way, here's a great niche for software as service! 顺便说一下,这里是软件服务的一个很好的利基!

The good news is that it's already possible to achieve something similar on Firefox, where you could change the browser setting to enable what they called "Silent Printing", you should set it to "Always" and you'll be good. 好消息是,已经可以在Firefox上实现类似的功能,您可以在其中更改浏览器设置以启用所谓的“无声打印”,您应该将其设置为“始终”并且您将会很好。

I'm sure IE might also have some way to do it, but I haven't found it yet. 我确信IE也可能有一些方法可以做到,但我还没有找到它。

Anybody know how's the state of printer and printing features offered by the other mainstream browsers such as Chrome and Opera? 有人知道其他主流浏览器(如Chrome和Opera)提供的打印机和打印功能的状态如何?

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>

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. 当您选择要打印的内容时,这将允许对话框保持不变。

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在定制OS元素方面非常灵活....

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..... 因此,用户可以通过他想要打印来定义打印机,您只需将打印机的名称传递给该功能,打印机就会开始打印.....

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! ) 用户可能希望能够控制何时激活他的打印机(想象一下讨厌的自动自动打印广告弹出窗口, ARRGH!
  • the user could want to specify printer settings (grayscale or color, resolution, size, ...) 用户可能想要指定打印机设置(灰度或颜色,分辨率,大小......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM