JavaScript Print

Monday, April 30, 2012

Giving your users a quick and easy way to print your web page is definitely a nice feature to have. We can use the JavaScript print function. Print is a method of the object "window", window.print(). The JavaScript print function performs the same operation as the print option that you see at the top of your browser window.


Here is an example on how to use the print function with a input element.

   <input type="button" value="Print" 
   	onClick="window.print()" />

Here is an example on how to use the print function with a link element.

<a href="javascript:window.print()">
    <img src="printImage.png" />

If you have printer friendly pages (not too many colors or background images), your users will enjoy this feature. While users can easily print without this JavaScript add-on, if you use it wisely, your users will appreciate it.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

JavaScript and jQuery: The Missing Manual Professional JavaScript for Web Developers HTML CSS and JavaScript Editor