23

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 ?

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,

Bharanikumar
  • 25,457
  • 50
  • 131
  • 201
  • 2
    How do you expect the user to pick which printer to print to? – Ignacio Vazquez-Abrams Nov 27 '10 at 15:34
  • 2
    @Ignacio Vazquez-Abrams: Most systems have the notion of a "default printer". However, printing from a browser w/o user confirmation sounds like a not-quite-great idea ("but OF COURSE all visitors of our website will want to have a printout of our new ad!" - pop-ups on the screen were bad enough) – Piskvor left the building Nov 27 '10 at 15:39
  • 1
    Firefox can be configured to print directly without showing the dialog, see http://forums.mozillazine.org/viewtopic.php?t=48336 – Nelson Oct 11 '13 at 12:19
  • in the case of a web application that is hosted on a company intranet you would know the printers and want to be able to have this kind of control. this is the situation i am in right now. – Taylor Brown Dec 16 '14 at 20:29

4 Answers4

9

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

--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.

user3288769
  • 105
  • 1
  • 1
6

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>
JoBaxter
  • 710
  • 2
  • 12
  • 23
  • Not sure. I just use IE on a windows PC. – JoBaxter Mar 08 '13 at 23:08
  • it doesn't work for me at IE 9.0.8112.16421. Does anybody known reasons of this? ActiveX control is allowed.. – Max Tkachenko Jun 08 '13 at 16:11
  • 1
    This is a function I have been looking for. I have tried the code above on a page, and its asking to install an Add-On. This seems to be from microsoft, but, Can anyone tell me: If I install this, will this give OTHER website the power to auto print using the same script? If so, is there a way to limit the Add-On to only one domain? – SW_Cali Oct 17 '13 at 10:21
  • 1
    This doesn't work on IE 9 + either, also I need something like this on chrome. For the same reason this answer describes. – Ákos Nikházy Nov 13 '17 at 10:18
  • 9
    This is an OLD IE ONLY solutuion. – CDT Feb 22 '19 at 07:09
  • tried same in angular app - not working – Kumaresan Sd Aug 11 '22 at 13:26
-4

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

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

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.....

Sandeep
  • 107
  • 1
  • 9
  • 1
    This was probably true in 2013, but Flash is end of life and I can't remember the last time I saw a browser with the Java plugin installed. – Quentin May 18 '21 at 07:44
-4

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, ...)
thejh
  • 44,854
  • 16
  • 96
  • 107
  • 1
    It is possible. Please see my comment. And my users are tellers who need to auto print when a transaction is posted. They print to the same printer with the default settings. Nothing ever changes other then the next person that walks up to the tellers window. – JoBaxter Mar 08 '13 at 23:13
  • 9
    -1 This is not the answer. Anybody knows why we need dialog. But there are a lot of scenarios where printing without dialog save time and money. In banking, for example. – Andrey Gubal Oct 16 '13 at 07:00
  • i don't buy this as an answer, more of a "you shouldn't do that" comment. I need exactly what the OP is asking for because I am trying to write a program that prints checks, and i cannot allow the user to use the print dialog for this. the accepted answer is close to what I am looking for. – Taylor Brown Dec 16 '14 at 20:24
  • I agree. Many scenarios for restaurants, online shops etc, where this would be very nice. – ahmed.hoban Mar 30 '15 at 18:48
  • 1
    this is discouraging. Bro, you need to be possitive – kuma DK Jun 04 '20 at 16:58
  • While this might be discouraging: it is correct. There are lots of things which are prevented by browsers because, while they are sometimes useful, they would be harmful if allowed to be triggered by any old webpage on the WWW. Point of Sale systems and the like need to look at other options (such as custom browsers and server-side printing). – Quentin May 18 '21 at 07:44