PRINTING WITH JAVASCRIPT

 

Lets say you write a really nice article or tutorial and you want to provide the user with the ability to print it out, while the user can always press CTRL + P or go to File > Print, however you can provide a special link that the user can click at the bottom of the article or maybe at the top and that link will automatically launch the printer dialog. Lets take a look at the code for this:
<a href="#" onClick="javascript:window.print()">print this page</a>

Notice how the small piece of JavaScript is inserted inside what seems like a regular link, thus providing us with a lot of different ways that we can twist this piece of code and customize to our needs.
First off we can always now hyper link a little image along side the text by simply adding the IMG tag in front of the text, like so:
<a href="#" onClick="javascript:window.print()"><img src="/images/print.gif"> print this page</a>

I wont go into every possible solution, since quite frankly they are endless, so I will simply leave you with a demo:

Print This Page

 

Hosted by www.Geocities.ws

1