How to print web page without prompt using JavaScript on Firefox

To print a web or HTML page without getting the usual printer prompt on your Firefox browser, you can make use of the Firefox plugin, JS Print Setup. Installation like usual installation of any Firefox plugins.

Once you’ve installed, follow the sample code presented on the plugin page, or try my example code below:

  <title>Test Print without prompt</title>
  <style>body {font-family:verdana,arial;font-size:10pt;background:white;} div {width:600px;border:3px solid #ccc;padding:3px;}</style>
  <script type="text/javascript">
  function print_doc()
		jsPrintSetup.setOption('orientation', jsPrintSetup.kPortraitOrientation);
		// set top margins in millimeters
		jsPrintSetup.setOption('marginTop', 15);
		jsPrintSetup.setOption('marginBottom', 15);
		jsPrintSetup.setOption('marginLeft', 20);
		jsPrintSetup.setOption('marginRight', 10);
		// set page header
		jsPrintSetup.setOption('headerStrLeft', 'My custom header');
		jsPrintSetup.setOption('headerStrCenter', '');
		jsPrintSetup.setOption('headerStrRight', '&PT');
		// set empty page footer
		jsPrintSetup.setOption('footerStrLeft', '');
		jsPrintSetup.setOption('footerStrCenter', '');
		jsPrintSetup.setOption('footerStrRight', '');
		// Suppress print dialog
		jsPrintSetup.setSilentPrint(true);/** Set silent printing */
		// Do Print
		// Restore print dialog
		jsPrintSetup.setSilentPrint(false); /** Set silent printing back to false */
 The document starts here ...<br/>
 This is test<br/>
 This is test<br/>
 This is test<br/>
 <input type="button" value="Print Now" onClick="print_doc();"/>

Please note the jsPrintSetup.setSilentPrint(true) indicates it will print without prompt. Please note this is Firefox-specific solution and each machine or computer that needs to have this function, will need to have the Firefox plugin installed. And this plugin even allows your flexibility of adjusting the margins to suit different printing environments. Try it out and let me know! Get the JS Print Setup plugin here.

Enter your email address to subscribe our newsletter or feed for FREE:

Delivered by FeedBurner

Bookmark with:

[Delicious]    [Digg]    [Reddit]    [Facebook]    [StumbleUpon]

0 Responses to “How to print web page without prompt using JavaScript on Firefox”

  1. No Comments

Leave a Reply

You must login to post a comment.