JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

Print Directly to Printer

Security Restrictions Block Access

By Stephen Chapman, About.com

Browsers do not make this multitude of browser and printer settings available to Javascript. Javascript is primarily concerned with modifying the current web page and so web browsers provide minimal information about the browser itself and next to no information about the operating system available to Javascript because Javascript doesn't need to know those things to perform thos things that Javascript is intended to do. Basic security says that if something like Javascript doesn't need to know about the operating system and browser configuration in order to manipulate the web page then it should not be provided with that information. It is not like Javascript ought to be able to change the printer settings to appropriate values for printing the current page because that is not what Javascript is for - that is the job of the print dialog. Browsers terefore only make available to Javascript those things that Javascript needs to know such as the size of the screen, the available space in the browser window to display the page, and similar things which help Javascript work out how the page is laid out. The current web page is Javascripts one and only concern.

Intranets are of course an entirely different matter. With an intranet you know that everyone accessing the page is using a specific browser (usually a recent version of Internet Explorer) and has a specific screen resolution and access to specific printers. This means that it makes sense on an intranet to be able to print directly to the printer without displaying the print dialog because the person writing the web page knows which printer it will be printed on.

The Internet Explorer substitute for Javascript (called JScript) therefore has slightly more information about the browser and operating system that Javascript itself does. The individual computers on the network running the intranet may be able to be configured to allow the JScript window.print() command write directly to the printer without displaying the print dialog. This configuration would need to be set up individually on each client computer and is well beyond the scope of an article on Javascript.

When it comes to web pages on the internet there is absolutely no way that you can set up a Javascript command to send directly to the default printer. If your visitors wish to do that they will have to set up their own "fast print" button on their browser toolbar.

Explore JavaScript

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Controls and Widgets
  5. Events
  6. Javascript has no access to the printer

©2009 About.com, a part of The New York Times Company.

All rights reserved.