W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2011

Re: [DOM3Events] defaultPrevented and preventDefault() conflict

From: Ojan Vafai <ojan@chromium.org>
Date: Wed, 9 Mar 2011 19:00:55 +1100
Message-ID: <AANLkTikwrAmb4bOoeGKPO67SqP_VwJmO6mqM0v3rQo2E@mail.gmail.com>
To: Anne van Kesteren <annevk@opera.com>
Cc: www-dom@w3.org
This seems to match the WebKit behavior as well.

Test case I used to verify:
<input id=foo>
<script>
var foo = document.getElementById('foo');
foo.addEventListener('click', function(e)
{e.preventDefault();alert(e.defaultPrevented)});
foo.addEventListener('blur', function(e)
{e.preventDefault();alert(e.defaultPrevented)});
</script>

This approach makes more sense to me since it gives more information to web
developers.

Ojan

On Sat, Mar 5, 2011 at 2:11 AM, Anne van Kesteren <annevk@opera.com> wrote:

> defaultPrevented says it reflects whether preventDefault() has been invoked
> for the event whereas preventDefault() says it only has an effect if the
> event is in fact cancelable. I think this has led to different
> implementations of these features in e.g. Opera and Gecko.
>
> In DOM Core defaultPrevented can only be true for cancelable events. (This
> is another reason why I changed initEvent() to also reset the "canceled
> flag" so that if you change an event from being cancelable to non-cancelable
> everything still makes sense.)
>
>
> --
> Anne van Kesteren
> http://annevankesteren.nl/
>
>
Received on Wednesday, 9 March 2011 08:01:46 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:07 GMT