How To Create A JavaScript Print Link

By  on  

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.

Recent Features

  • By
    5 More HTML5 APIs You Didn&#8217;t Know Existed

    The HTML5 revolution has provided us some awesome JavaScript and HTML APIs.  Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers.  Regardless of API strength or purpose, anything to help us better do our job is a...

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

Incredible Demos

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!