javascript print without print dialog box

0 votes
asked Nov 27, 2010 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 ?

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,

5 Answers

0 votes
answered Nov 27, 2010 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, ...)
0 votes
answered Nov 11, 2012 by user1447134

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.

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

I'm sure IE might also have some way to do it, but I haven't found it yet.

Anybody know how's the state of printer and printing features offered by the other mainstream browsers such as Chrome and Opera?

0 votes
answered Nov 5, 2013 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>
0 votes
answered Nov 23, 2013 by sandeep

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

0 votes
answered Nov 11, 2014 by user3288769

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.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...