Bypass / Disable print dialog box in firefox with javascript print()

Just print!

In my ePoS system project, I have the need to open a popup with javascript and print the contents without seeing the dialog box.

Everywhere I searched, there were the ‘you don’t wanna do that because….’ from know it all keyboard warriors saying it was bad because evil doers could send porn to your printer.

What about intranets and web apps?

Finally, I figured it out and as long as you’re using Firefox and you have access to it then you’re ready to make it print without a nasty dialog…

  • Open firefox and put about:config in the address bar and press enter (you will need to click the button that shows to say you know what you’re doing)
  • Type print.always_print_silent in the filter box at the top
    If you have an entry already there and it is set to false just right click it and choose ‘toggle’ to set it to true.
    If there is no entry there already then follow on…

    • right click the screen and choose New->boolean
    • enter print.always_print_silent as the preference name when asked and press enter
    • set boolean value to true and press enter

That’s it, you will no longer see the dialog box when you print. Beware though, it will try to print to the last printer you used when you had the dialog box open. If you ever need to change it then you will need to toggle the value for print.always_print_silent by following the above steps.

Open a javascript popup and print the contents

Now you can print without dialogs, you can use the following code to open a popup window and print it.

open the popup


windowname = window.open('url.html','name',options);

the options you have available are:

Option Values Description
location yes|no Does the location bar show?
menubar yes|no Does the menubar show?
scrollbars yes|no Do scrollbars show?
status yes|no Does the status bar show|
titlebar yes|no Does the titlebar show?
toolbar yes|no Does the toolbar show?
resizable yes|no Can you resize the window?
height pixels height of window
width pixels width of window
directories yes|no Does the personal toolbar show?
innerHeight pixels specifies the inner height of window
innerWidth pixels specifies the inner width of window
screenX pixels specifies distance from left edge of screen
screenY pixels specifies distance from top edge of screen

For example, to open a pop window showing the file called example.html with no menu bar, with a width of 430 pixels, height of 700 pixels, no toolbar, with scrollbars and with the window you would use this command


winname = window.open('/example.html','newwin','menubar=no,width=430,height=700,toolbar=no,scrollbars=yes,screenX=300');

To close that window, you can add this


winname.close();

To print the window, you can add this to the example.html page


self.print();

or to print it from the calling page, you might need to pause for a little while before issuing the print command so it has time to load the page content first..


setTimeout("winname.window.print();",500);

All the commands need to be within <script> /script tags

About Andy

This is my personal website where I (occasionally) post about things going on in the world of me. I am the creator of CommentLuv and administrator of comluv.com
Code , , , , ,

18 responses to Bypass / Disable print dialog box in firefox with javascript print()


  1. Script for print() is really helpful for me. Can this code working with Internet explorer ?

  2. I have tried this and It works…
    Thanks for sharing this tutorial…

    By the way, Can I apply this tutorial in other web browsers?
    Andryan recently posted..Kompetisi WEB Kompas MuDA & AQUAMy Profile

  3. hi…
    Deknor from thailand visit your blog..
    nice informasion here….i like it..
    but i stillanew blogger..
    need more information about blogging so i came here with neural search engine from google…
    I like your blog…
    happy blogging…
    DekNor recently posted..UViOoMy Profile

  4. Thanks for the information it worked for me..

  5. thank you for the precise and extensive information. winname.close() will be very useful.
    Raffaello Tamagnini recently posted..Riccione entra nella rete telematica regionaleMy Profile

  6. It works for me too, thanks for the script it does help me little by little with my java knowledge.

  7. thanks for sharing fiddyp :) and thanks for the tutorial
    daus recently posted..Apple Ipad2 Bakal Dilancarkan Dapatkan Percuma Di DenaihatiMy Profile

  8. Whoa – that’s really neat and it worked for me! Great step by step directions.
    Turbo Traffic System recently posted..Turbo Traffic System BonusMy Profile

  9. Great work, if you are happy doing this and it can improve your local system I don’t see anything wrong with it. Do you have a javascript button that will load the popup, print and close all in one click?
    Gary Corbett recently posted..Hacker NewsMy Profile

  10. acemilikce

    Script for print() is really helpful for me :/

  11. Great tutorial. It really worked. Thanks for sharing.

  12. Nice one. I never knew about print.always_print_silent, that can prove really useful sometimes.
    Ayanami recently posted..16617- 11 апреля 2011 в 12-03 в разделе -mu-My Profile

  13. I’ve had issues with the print function before. So, hopefully this fixes it
    Charleston Wedding Photographer recently posted..Amber Bridal Portrait Middleton PlantationMy Profile

  14. Nice article! It will probably help me!
    Shubham recently posted..Everything you need to know about the iPad 2My Profile

  15. Worked for me! Thank you for this bit of info!

  16. it is really helpful to me

  17. Ramon Rossen

    I’ve tried it too and it really works for me how about you guys here?? By the way thanks for this great tutorial ever I learn a lot of things.

  18. Thanks for heads-up! it’s quite easy to implement.
    David Britt recently posted..Emergency Locksmiths YokineMy Profile

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge