W3C home > Mailing lists > Public > w3c-wai-ig@w3.org > January to March 2003

Re: to js or not to js?

From: Jim Ley <jim@jibbering.com>
Date: Mon, 20 Jan 2003 12:02:44 -0000
To: w3c-wai-ig@w3.org
Message-ID: <b0goef$9hm$1@main.gmane.org>

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

> 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.)

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 20:36:13 UTC