Quackit Logo

Got a MySpace Page?

Get "www.yourname.com" for your MySpace page. Learn how >>.

JavaScript Print

Print Version

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. Also, this code can be triggered automatically upon loading a printer friendly version.

To create a "Print this page":

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>

The above code results in the following:

Print this page

To automatically open the print dialogue box:

You can call the JavaScript print function upon loading a Printer friendly version. This will automatically open the print dialogue box for the user.

  1. Copy and paste the following code in between the <HEAD> and </HEAD> tags of the printer friendly version:
    <script language="Javascript1.2">
      <!--
      function printpage() {
      window.print();  
      }
      //-->
    </script>
    
  2. Add the following to your <BODY> tag:
    onload="printpage()"

So, your body tag should look something like this:

<body onload="printpage()">

Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
                     
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!