HTML / Javascript One Click Print (no dialogs)

I ended up implementing a custom application that works very similar to the Nexus Mod Manager. I wrote a C# application that registers a custom Application URI Scheme. Here's how it works:

  1. User clicks "Print" on the website.
  2. Website links user to "CustomURL://Print/{ID}
  3. Application is launched by windows via the custom uri scheme.
  4. Application communicates with the pre-configured server to confirm the print request and in my case get the actual print command.
  5. The application then uses the C# RawPrinterHelper class to send commands directly to the printer.

This approach required an initial download from the user, and a single security prompt from windows when launching the application the first time. I also implemented some Javascript magic to make it detect whether the print job was handled or not. If it wasn't it asks them to download the application.


I am writing this answer for firefox browser.

  • Open File > Page Setup

  • Make all the headers and footers blank

  • Set the margins to 0 (zero)

  • In the address bar of Firefox, type about:config

  • Search for print.always_print_silent and double click it

  • Change it from false to true

    • This lets you skip the Print pop up box that comes up, as well as skipping the step where you have to click OK, automatically printing the right sized slip.
  • If print.always_print_silent does not come up

    • Right click on a blank area of the preference window

    • Select new > Boolean

    • Enter "print.always_print_silent" as the name (without quotes)

    • Click OK

    • Select true for the value

  • You may also want to check what is listed for print.print_printer

    • You may have to choose Generic/Text Only (or whatever your receipt printer might be named)

I know this is a late reply, but here's a solution I'm using. I have only used this with IE, and have not tested it with any other browser.

This Sub Print blow effectively replaces the default print function.

<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

Then use Javascript's window.print(); ties to a hyperlink or a button to execute the print command.

If you want to automatically print when the page loads, then put the code below near tag.

<script type="text/javascript"> 
window.onload=function(){self.print();} 
</script> 

Tags:

Html

Printing