Copyright ©

Javascript - Page Printing

previous next


Many times you would like to give a button at your webpage to print out the content of that web page via an actual printer.

JavaScript helps you to implement this functionality using print function of window object.

The JavaScript print function window.print() will print the current web page when executed. You can call this function directly using onclick event as follows:

<script type="text/javascript">
<input type="button" value="Print" onclick="window.print()" />

This will produce following button which let you print this page. Try it by clicking:

This serves your purpose to get page printed out, but this is not a recommended way of giving printing facility. A printer friendly page is really just a page with text, no images, graphics, or advertising.

You can do one of the followings to make a page printer friendly: