Re: Using Form Elements for Pages only Intended for Printing

 "Jon Hanna" <jon@spinsol.com>

> 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>')
> }

Well it's better (but having it as an external script seems very
wasteful.) but it's still not perfect, you're now assuming the
javascript: pseudo protocol exists, which is unwarranted, also why have
the DIV?

if (window.print) {
 document.write('<a href="somepage.html" ')
 document.write('onclick="if (window.print) window.print(); return
false">')
 document.write('Print this page</a>')
}

Where sompage.html is meaningful as it can still fail in a number of
(rare) scenarios.

Jim.

Received on Thursday, 10 January 2002 10:06:14 UTC