CoverYourASP --> Making a printer-friendly version of your page

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
87 active users
9169 visitors today
8514 pages today
how is this done?
Tools I use

Copyright © 1999-2016 James Shaw.
All rights reserved.

RSS submissions

Now open source with SourceForge!

Since I added the "Printer-friendly page" option on the left of the page I've noticed quite a few failed searches for a description of how it works. So here it is!

It's very simple. The link on the left of the page is made up from the following code in utils/Header.asp, designed to call the current page with "plain" added to the URL.

// get name of current page
var sPage = '' + Request.ServerVariables ( "SCRIPT_NAME" );

// get QueryString if there is one
var sQuery = '' + Request.QueryString ( );

if ( sQuery != '' )
   sQuery += '&';

Response.Write ( '<a href="' + sPage + '?' + sQuery + 'plain">Printer-friendly page</a>' );

Since the URL of the page may already have some parameters in the QueryString (the part following a ? in the URL), I either have to add ?plain or &plain.;

The "plain" in the URL is detected in utils/Init.asp, and the bPlainJane variable set when it is found:

// if we're passed in 'plain' in the querystring we'll make
// the page as plain as possible for printing
bPlainJane = Request.QueryString ( 'plain' ).Count;

Note that although I use the b prefix to imply the variable is a boolean, it really is the number of "plain" parameters in the URL. I just use it as a boolean expression.

Then it's a simple matter of testing bPlainJane where there is content that you want to add or remove for the plain version of the page. As an example, a new header is shown at the top of the printer-friendly page with this code in utils/Header.asp:

// should we make a plain page for printing?
if ( bPlainJane )
   // table containing rest of body
   Response.Write ( '<table bgcolor="#ffffff" width="600" border="0" cellpadding="0" cellspacing="0">' );
   Response.Write ( '<tr><td align="center"><h5>You are viewing a plain-jane printable version</a></td></tr><tr>' );
   // display left navigation bar

In fact this code not only displays a new header, but it also uses a narrower fixed-width table to contain the page, and stops the left navigation bar displaying. In a similar manner the right side of the page is removed.

Try it out!

Featured sponsor
My favorite resources

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?

I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...