[whatwg] Return values of on* event handlers

Stewart Brodie stewart.brodie at antplc.com
Mon Jul 24 02:29:50 PDT 2006


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



More information about the whatwg mailing list