XHanch Studio Log in | Register | Cart

Forum

Notifications
Clear all

[How to] Print current web page with JavaScript

1 Posts
1 Users
0 Likes
1,121 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

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:

<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:

<script type="text/javascript">
<!--
    window.print();
//-->
</script>
 
Posted : 16/03/2011 12:37 am
Share:

× Close Menu