Printing JavaScript Output

JavaScript FAQ | JavaScript Dialogs FAQ  

Question: How do I print JavaScript output?

Answer: JavaScript programs cannot directly access printers. However, the users still can print out everything on the Web page, including the output of JavaScript programs, by using the File | Print menu of the browser (or the keyboard shortcut, e.g. Ctrl+P on Windows systems).

If your script outputs data that users would often print out, then you can

  • remind them to use the File | Print menu, press Ctrl+P and/or
  • use the window.print() method to open the Print dialog.
Also, your script might generate the printable data in a separate browser window, as shown in the example below.

Example. This script generates the multiplication table, writes it to a new browser window and explains to the user how to print it.

See also other JavaScript dialogs:

  • Alert (message box) dialog
  • Confirm dialog
  • Prompt dialog
  • Find dialog
  • Add Favorite dialog
  • Copyright © 1999-2011, JavaScripter.net.