How To Create A JavaScript Print Link

Written by David Walsh on November 28, 2007 · 1 Comment

Oftentimes a novice web user wont think to do something unless they are presented with the option to do so. I've found this to be true of many of the websites I make. I've added "email to a friend" functionality to customer websites and traffic seems to increase (albeit a fraction, but every bit helps).

Some websites are helped by adding a JavaScript "print" link. If you have a page with a coupon, for example, or a page that acts as a promotional piece, I recommend adding a "print" link. Users will get your subtle message and that could mean increased business / traffic.

The Code

Some quick JavaScript in the "href" attribute of the anchor will accomplish this goal.

<a href="javascript:window.print();">Print</a>

Be sure not to put the JavaScript in the onClick attribute of the anchor -- not everyone clicks a link.

Comments

  1. Aslam C May 19, 2012

    We can use javascript:window.print()..

    for example :-

    we can all it with 'href ' also.


    print this page

Be Heard

Tip: Wrap your code in <pre> tags or link to a GitHub Gist!

Use Code Editor
Older
How To Create A JavaScript Close Link
Newer
Prevent Double Margin & Padding In IE6 When Using CSS Float