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:
19
12

More JavaScript Help:
» What is the difference between synchronous and asynchronous requests?
» JavaScript random number?
» How can I disable my submit button if the textarea in my form is empty?
» How to download free scripts?
» How to do fingerprint with Javascript?
» How to make simple program of Contextmenu in javscript.......? plz snd me the source code of the program..
» How to submit a form to open in a popup window?
» What is the best method of form validation with JavaScript?


Leave a Comment on "JavaScript Print"
You must be logged in to post a comment.

Link to This Question!
GET OUR NEWSLETTERS