Helping ordinary people create extraordinary websites!
   

JavaScript Print

Sunday, 27th September 2009
by Omar


I am trying to setup a link that will allow a user to print the current page using JavaScript. It should open the print dialog box and then from there the user is able to print using their desired printer.



Vader
Hi Omar,
There are a few ways to go about setting up a JavaScript print option all of which use the window.print() function. The print function opens the print dialog box as you mentioned and gives the user the choice of printer and options.

JavaScript Print via text link
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
<a href="javascript:window.print()">Print Me!</a>


JavaScript Print via image link
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
<a href="javascript:window.print()"><img src="/images/print_button.gif" /></a>


Automatically calling the print function
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
In the body of your page you can add the print function to your onLoad event. This is typically used when a user options a printer friendly version of your page as their action would hint their intention to print.

<BODY onload="window.print()">


V.
Monday, 28th September 2009
Votes:
32
28

More JavaScript Help:
» How can I resize a window to a specific size using JavaScript?
» Encrypt the user inputted word with additional 3 letters?
» Javascript cookies to redirect user if submit button is already hit.
» How can I control a group of checkboxes with only 1 check?
» JavaScript History Back
» How to submit a form using JavaScript?
» Dynamic fields in: document.getElementById('<%= lstFieldList_TrajectType(0)%>').value
» Write a javascript code that verifies all textboxes has been filled.