A Hyperlink to "Print"

Question: How do I write the code whereby when I click on the hyperlink - "print", it will pop up the screen on printer settings without having to go to File -> Print -> printer settings screen.

Answer: The code to produce a "print" hyperlink is an extremely simple call to a javascript function.

 <a href="#" onclick="window.print();return false;">print</a> 

That's all there is to it, the window.print() command opens the printer settings screen when someone clicks on the link and return false makes sure the href= gets ignored. The href is set to the top of the current page just in case someone accesses the page with a browser that doesn't support Javascript or with Javascript turned off.

If you prefer a button rather than a hyperlink then that's easy too. It looks like this:

and you code it like this:

 <form><input type="button" value=" Print this page " 
onclick="window.print();return false;" /></form>


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow