Alternate Page to Print

Question: I'm wanting to set up a command that automatically prints a different page from the page the user is currently on without having to actually open that other page. So 'page one' with have the button "Print this page" and when it is clicked the page that prints out is actually 'page two'. Is this possible? Any help would be most welcome. Thanks in advance.

Answer: This is possible, but only if your visitors are using Internet Explorer 4 or later. Visitors using any version of Netscape, Opera, or other web browsers will get a print of the current page instead of your alternate one.

To get Internet Explorer to substitute an alternate page to be printed out when your visitors select to print the current page you include the following code inside the <head> section of your page:

<link rel="alternate" media="print" href="altpage.htm" />

Just substitute the filename or web address of the alternate page that you want to print for altpage.htm in the code shown. Note that the file must be loaded to your web server in order to be available to be printed.

If you want to make a variant of the same page with the same html content but different CSS markup then you can do this by including two stylesheet links in your page and use the media attribute to define when to use which. For example you might code:

<link rel="stylesheet" href="print.css" type="text/css" media="print" />
<link rel="stylesheet" href="screen.css" type="text/css" media="screen" />

This allows you to have different ways of formatting the page for screen and paper and works with Internet Explorer, Opera, and Netscape 6 (and later) but doesn't work with Netscape 4 where the screen CSS will over-ride the formatting even for printing (as Netscape 4 doesn't understand the media parameter).

If you want something that will work in all browsers then the only option is to include a link to the print-friendly version of the page on the page itself so that your visitors can click that link, open the new version of the page, and then print.

You can incorporate more than one of these into the same page. Include all three link statements and IE will print the alternate page while Opera and Netscape 6+ will print the current page but using the alternate formatting from the print CSS. All you need then is to incorporate some Javascript that adds a printer friendly link when Netscape 4 (or another browser where we don't know what support is available) is used and doesn't add it for Internet Explorer, Opera, or Netscape 6+. This code would look something like the following:

<script type="text/javascript">
if ((navigator.appName.indexOf('Internet Explorer') == -1 &&
navigator.userAgent.indexOf('Opera') == -1 &&
navigator.appName.indexOf('Netscape') == -1) ||
(navigator.appName.indexOf('Netscape') != -1 && browserVersion < 6)) {
document.write('<a href="altpage.htm">Printer Friendly Version<\/a>');


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow