Re: to js or not to js?

"Jon Hanna" <jon@spin.ie> wrote in message
news:NDBBLCBLIMDOPKMOPHLHKEJJEMAA.jon@spin.ie...

> It's important to note that we already know that all javascript browsers
> have a document object. Otherwise we'd have to test if(document) first.

That assumption is actually unwarranted... (although the only definitive
counter example I can come up with are SVG viewers not HTML ones)
window.document (which is the same as just document) is not in any standard,
it can't really be relied upon.

> /*we're going to have to break the back button, but presumably it's
> important enough that we go ahead and do it*/
> location.href = URI;

You never checked for the existence of the location object, before checking
the properties, also location="URI" (rather than location.href) is generally
prefered due to browser bugs with .href, including crash bugs.

> if (self.print){
> /*we can print from javascript, so therefore there is no risk in offering
> to do so*/
> document.write('<p><a href="#" onclick="self.print(); return false;">Print
> this page</a></p>');

You need to check for document and document.write too, also in the specific
example of testing for methods on the global scope (such as self/window/top
etc.) you should check the type of the method too, since having an element
on the page with id "print" will also cause if (self.print) to evaluate to
true, however self.print() will result in an error.   (on a usability note,
you also don't print this page to appear in a link, since it's unlikely to
work in a list of links context, the link only being activated onclick.)

Jim.

Received on Monday, 20 January 2003 07:02:51 UTC