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
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

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

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    Do / Undo Functionality with MooTools

    We all know that do/undo functionality is a God send for word processing apps. I've used those terms so often that I think of JavaScript actions in terms of "do" an "undo." I've put together a proof of concept Do/Undo class with MooTools. The MooTools...

  • By
    CSS Vertical Center with Flexbox

    I'm 31 years old and feel like I've been in the web development game for centuries.  We knew forever that layouts in CSS were a nightmare and we all considered flexbox our savior.  Whether it turns out that way remains to be seen but flexbox does easily...

Discussion

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