[How to] Print current web page with JavaScript

Started by Xhanch Studio, March 15, 2011, 05:37:59 PM

previous topic - next topic
Go Down

Xhanch Studio

You can use JavaScript to automatically open print dialogue box so that users can print the page. Although most users know they can do something like File > Print, a Print this page option can be nice, and may even encourage users to print the page. Also, this code can be triggered automatically upon loading a printer friendly version.

The following code creates a hyperlink and uses the JavaScript print function to print the current page:
Code Select
<a href="JavaScript:window.print();">Print this page</a>

To automatically open the print dialogue box, copy and paste the following code after the </body> tag:
Code Select
<script type="text/javascript">
Best Regards,
Susanto B.Sc
Web development services, WordPress plugin and theme development, PSD to XHTML conversion - http://xhanch.com
Read free manga online - http://authrone.com

Go Up