W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2006

[whatwg] Return values of on* event handlers

From: Stewart Brodie <stewart.brodie@antplc.com>
Date: Mon, 24 Jul 2006 10:29:50 +0100
Message-ID: <bac92ee0039eb80240a3fdeb2bea7f7105f3e846@localhost>
Dean Edwards <dean at edwards.name> wrote:

> Boris Zbarsky wrote:
> > Consider the following testcase:
> > 
> > <!DOCTYPE html>
> > <a href="http://www.example.com" onclick="return 0">Click me</a>
> > 
> > Should clicking the link load www.example.com?
> > 
> 
> Yes. You should explicitly return "false" to cancel an event.

I've had to deal with customer fault reports saying that "return 0" should
cancel the event, so have to allow for numbers here too.  I'm assuming that
means that one or more of the major desktop browsers permits this.


> Most event handlers return nothing (undefined) which is equivalent to
> false [...]

Yes, the code that invokes the event handler must be extremely careful to
examine the type of the return code to avoid unfortunate type conversions.


-- 
Stewart Brodie
Software Engineer
ANT Software Limited
Received on Monday, 24 July 2006 02:29:50 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:47 UTC