
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









Script for print() is really helpful for me. Can this code working with Internet explorer ?
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 & AQUA
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..UViOo
Thanks for the information it worked for me..
thank you for the precise and extensive information. winname.close() will be very useful.
Raffaello Tamagnini recently posted..Riccione entra nella rete telematica regionale
It works for me too, thanks for the script it does help me little by little with my java knowledge.
thanks for sharing fiddyp
and thanks for the tutorial
daus recently posted..Apple Ipad2 Bakal Dilancarkan Dapatkan Percuma Di Denaihati
Whoa – that’s really neat and it worked for me! Great step by step directions.
Turbo Traffic System recently posted..Turbo Traffic System Bonus
Twitter: garycorbett1
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 News
Script for print() is really helpful for me :/
Great tutorial. It really worked. Thanks for sharing.
Twitter: ayanami_rei
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-
I’ve had issues with the print function before. So, hopefully this fixes it
Charleston Wedding Photographer recently posted..Amber Bridal Portrait Middleton Plantation
Twitter: newtab_blog
Nice article! It will probably help me!
Shubham recently posted..Everything you need to know about the iPad 2
Worked for me! Thank you for this bit of info!
it is really helpful to me
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.
Thanks for heads-up! it’s quite easy to implement.
David Britt recently posted..Emergency Locksmiths Yokine