Skip to main content

Bug Tracker

Side navigation

#7876 closed feature (fixed)

Opened December 30, 2010 10:37PM UTC

Closed December 31, 2010 03:08PM UTC

Last modified April 23, 2011 06:08PM UTC

IE dblclick documentation error

Reported by: rtpmatt Owned by: rtpmatt
Priority: low Milestone: 1.6
Component: web Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

The docs for dblclick say

 It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events and others only one. If an interface that reacts differently to single- and double-clicks cannot be avoided, then the dblclick event should be simulated within the click handler. We can achieve this by saving a timestamp in the handler, and then comparing the current time to the saved timestamp on subsequent clicks. If the difference is small enough, we can treat the click as a double-click. 

In IE (8 at least) however, the second click even is not fired, only the first click, then a dblclick.

http://www.jsfiddle.net/b4ktR/

The best solution I have come up with is to use the timer as proposed, but if a dblclick event is fired, have it do what the timer would do in the case of a dblclick, cancel the timer, and return false; There is probably a better way, but that what I have right now.

Sorry if this is not the best place to post a documentation issue.

Attachments (0)
Change History (7)

Changed December 30, 2010 11:49PM UTC by ajpiano comment:1

owner: → rtpmatt
status: newpending

Is this a docs error? It describes exactly what you do:

"The sequence of events triggered varies from browser to browser, with some receiving two click events and others only one."

Unless you are saying that it is *also* worth mentioning one could use a timeout based approach? Is that what you're getting at?

Changed December 31, 2010 02:30AM UTC by anonymous comment:2

No, I am saying this is perfectly valid and true:

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events and others only one.

but this:

the dblclick event should be simulated within the click handler.

obviously can't work in a browser that only fires a single click.

Changed December 31, 2010 02:52AM UTC by dmethvin comment:3

obviously can't work in a browser that only fires a single click.

Sure it can, using the timer trick mentioned in the documentation. That's basically what either the browser or underlying operating system is doing to detect double clicks. I think the docs are okay as-is, but if you have some suggestions on rewording let us know.

It's a really bad idea to use double clicks in a web interface, it's not something that most people expect.

Changed December 31, 2010 03:44AM UTC by RTPMatt comment:4

Unless I am missing something and just being an idiot (quite possible), if I only have a click handler, and the browser fires a click and then a dblclick, checking the time between click will do no good, as the second click will be ignored because I have nothing bound to dblclick. ''The second click event is not fired even if no event is bound to dblclick.''

If instead I have something bound to click that does the time checking, and something bound to dblclick for the browsers that use only it, I will be double firing my dblclick in browsers that give me two clicks and a dblclick.

It's a really bad idea to use double clicks in a web interface, it's not something that most people expect.

I totally agree with that, however, if the docs propose a possible solution, I feel it should work, or not be provided.

I think the docs would be better if they did one of the following:

1. Just stated the problem

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events and others only one.

2. State the problem and give some advice on how to fix it, but not make it sound like a complete solution if it is not.

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click and one dblclick event and others only a single click and dblclick event. You can get around this by checking the time between click/dblclick events, and manually firing your event when appropriate.

3. Providing a solid method to make it work. I do not have a good example for how to do this. I am sure it can be done, but I was more interested in making it work for my case than coming up with the perfect solution.

If you still disagree with me, please close this ticket and I will not bring it up again.

Changed December 31, 2010 03:08PM UTC by dmethvin comment:5

resolution: → fixed
status: pendingclosed

Ah, okay, I see what you are saying. The docs wording is ambiguous. I think it essentially means "making an element respond to both click and double-click is not a good idea. But you forge ahead and do it anyway, the solution may involve attaching both a click and double-click handler so it can work on all browsers." Does that sound right?

I think it may be best to remove any prescriptive attempt at a solution here, so that's what I've done. There is a user comment on the page that includes a link with code, in case anyone wants to do it.

Changed January 01, 2011 07:26AM UTC by rtpmatt comment:6

Thank you, I very much like the "vary by operating system and browser, and is often user-configurable." as that has been on my mind a lot recently.

Changed April 23, 2011 06:08PM UTC by john comment:7

component: unfiledweb
priority: undecidedlow