Print using JavaScript

If you would like to print your HTML page contents using your printer, here is a one line javascript:

<a>href="" onclick="window.print();return false;" ><img  src="../images/print.gif" border="0" alt="Print" /></a>

Code Explain:

<a href=”” : This is for the mouse hand to appear when mouse hover over print icon.

onclick=”” : event handler works when you click on the print icon.
window.print() : a javascript command that calls windows print screen.
return false; : so that after you print it will not come back and seach for the no page in href=””
: print image tag.
border=”0″ : to delete border, otherwise a border will appear.
src=”../images/print.gif” : the path for print icon.
../ : means go back one step.

Advertisements

About Ahmed

Software craftsman, programmer, developer, system/business analyst, DBA and PM.
This entry was posted in HTML, JavaScript, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s