W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2011

Re: onclick after removing element from document during onmouseup

From: Glenn Maynard <glenn@zewt.org>
Date: Sun, 8 May 2011 23:01:40 -0400
Message-ID: <BANLkTi=_qM8OUzSUrn8Mw0TdGdfHfijGAg@mail.gmail.com>
To: Ryosuke Niwa <rniwa@webkit.org>
Cc: www-dom@w3.org
On Sun, May 8, 2011 at 10:10 PM, Ryosuke Niwa <rniwa@webkit.org> wrote:

> Example below.  In FF3/4, when the link is clicked, no click event is
>>> dispatched and the link doesn't activate.  In Chrome 9, the click event
>>> still fires.  (This doesn't happen with keydown/keypress; for that event
>>> sequence, both browsers match FF.)
>>> I think Gecko's behavior makes more sense.  I can't find this in the
>>> spec--is this covered?
> Why?  Are there websites that break due to WebKit's current behavior?

The browser is dispatching an event to an element that isn't in any
document.  That means clicks can't reliably be captured; the document isn't
an ancestor of the node when event dispatch happens.

For example, it's very useful to capture click at the window, to request
authentication when certain things are clicked.

 <a href="http://www.google.com" id="test">test</a>
>>> <script>
>>> var elem = document.getElementById("test");
>>> elem.addEventListener("mouseup", function(e) {
>>>         elem.parentNode.removeChild(elem);
>>> }, false);
>>> </script>
>> Any input on this?  I've hit variants of this issue more than once.
>> For example, with a dropdown menu open, the user can middle-click on a
>> menu item to open it in a tab.  The script hides the menu on mouseup.  In
>> WebKit this did what was intended: the menu closed and the menu item opened
>> in a tab.  In Firefox it didn't: the menu was closed but the default action
>> didn't happen.
>> (I'm not overly concerned with which behavior is correct, only with the
>> interoperability failure that resulted.)
> It's definitely nice to spec this but I'd like to know which behavior is
> more preferable or predominant.  Have you tested IE & Opera?

Testing with the above, Opera is inconsistent.  When left-clicking the link,
no onclick is received and the new page is not loaded.  However, when
middle-clicking the link, the page *is* loaded in a tab.  (I imagine
slightly different things are happening, since there's no click event for a
middle-click anyway.)

In all cases matching Firefox, if the node is removed and immediately
reinserted at the same position, the behavior is unchanged: onclick doesn't
happen.  (In other words, they're remembering that the node was removed, not
checking that it's still in the document later.)

Glenn Maynard
Received on Monday, 9 May 2011 03:02:08 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:17 UTC