RE: Using Form Elements for Pages only Intended for Printing

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> We wanted to
> add a "Print" button to make it clearer, but that turns out to
> require JavaScript to work, and we were aiming for WAI Pri. 1.

Not only does it need javascript to work, but it also needs to has to
be on a subset of those browsers with javascript - many will error if
you try to run the print command.
However, all is not lost, the following will only appear on those
browsers which allow printing via javascript:

Put this where the button or link should be:

<script type="text/javascript" src="print.js"></script>

print.js is as follows:

if (self.print){
	document.write('<div><a href="javascript:self.print();">Print This
Page</a></div>')
}

This works because self.print returns either a function reference or
nothing depending whether printing is available, which gets cast to
true of false respectively.

It will print on NS4+ and IE5+, I don't know about the other browsers
(there is a really weird way of printing from js in IE4, but unless
you have a strong need to allow IE4 to print as well you are better
off leaving alone). On the other browsers you've done no harm, so no
WAI violation.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPD2rd4Fpv9f1Mr0YEQKjzwCeLaDHjSpTGgUouIamEIJGLyOMmSsAmgJP
nhXvspZdhA6LdF37xSm1KrJk
=0eGZ
-----END PGP SIGNATURE-----

Received on Thursday, 10 January 2002 09:56:12 UTC