- From: Jonas Sicking <jonas@sicking.cc>
- Date: Sun, 08 Jun 2008 23:34:55 -0700
- To: Travis Leithead <travil@windows.microsoft.com>
- Cc: "public-webapi@w3.org" <public-webapi@w3.org>, Doug Schepers <schepers@w3.org>
Travis Leithead wrote: > Interesting findings (mostly related to IE): > > This test tries to define if the HTML event handlers (onFoo) are linked to the add/removeEventListener APIs in any way (or to define what the relationship is). > > Browsers tested: Opera 9.25, Firefox 3 RC1, IE8 Beta1, Safari 3.1.1. > > (on IE, I substituted attach/detachEvent for add/removeEventListener) > > The findings appear to indicate that: > > 1. All tested browsers follow a basic model in that an HTML event > handler is maintained separately (perhaps in a separate queue) from > event handlers attached via programmatic means (e.g., > addEventListener/attachEvent). This can be verified by adding an HTML > event handler and then trying to delete the reference to its DOM > attribute via removeEventListener. This is not true. You are assuming that the EventListener object used for onfoo attributes is the onfoo object itself. This is not the case in firefox, nor would I expect it to be the case anywhere else. Instead we create a separate EventListener object which wraps the onfoo object and deals with things like calling .preventDefault() if the onfoo object returns false. It also does lazy compilation when onfoo is set via setAttribute("onfoo", "your code here"); In firefox i think onfoo listeners do go in the same list as other event listeners, however you can't get to the EventListener object itself, so you won't be able to remove it using removeEventListener. A better way to test for this would be something like: myElem.addEventListener("click", listener1, false); myElem.onclick = listener2; myElem.addEventListener("click", listener3, false); And then check in which order the three listeners are called. If attribute listeners end up in the same list as "normal" listeners then the calling order should be: listener1, listener2, listener3. > In addition to this basic conclusion, there were a few discrepencies in event handling that should be noted: > > * IE/Firefox/Opera all keep a reference alive to the HTML event handler via the element's 'onclick' DOM attribute even after the content attribute has been removed. Hmm.. this sounds like a bug to me. I would have expected .removeAttribute("onclick") to remove the .onclick attribute. / Jonas
Received on Monday, 9 June 2008 06:36:18 UTC