Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

printing out the content

I just finished the lesson on print style sheets. What would I need to do to add a "print" button to a website so the viewer could just click on it rather than having to use control-p?

1 Answer

Excellent question. One way to accomplish this would be making use of the JavaScript window.print() method. For example, in an anchor tag:

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

Clicking that link would bring about the system's print dialog to print out the current window. There's an excellent article over at CSS-Tricks about this.

Also, for future reference, please categorize your post. For example, instead of 'General Discussion', a better category for it would be 'HTML' or 'CSS'. This allows everyone to give each other help faster :-)

Best of luck! Print stylesheets are always fun.