Open Bug 1048294 Opened 10 years ago Updated 1 year ago

MouseEvent.Which always reports the same wrong value (1)

Categories

(Core :: DOM: Events, defect, P5)

x86_64
Windows 7
defect

Tracking

()

People

(Reporter: Dexter, Unassigned)

Details

(Keywords: dev-doc-needed)

Attachments

(1 file)

As reported by the MouseEvent MDN documentation (https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.which), the |which| property of the MouseEvent event caught on 'mousemove' should report |0| when no mouse button is pressed and |1| when the left mouse button is pressed (and so on with the other mouse buttons). Unfortunately, this property always contains |1| even when no mouse button is pressed. I'm attaching a little sample page to reproduce the problem: 1) Open the attached page; 2) Move the mouse on the canvas; 3) It should print "Mouse Which 0" (works on Chrome) but it prints "Mouse Which 1".
I am able to reproduce this on Ubuntu 12.04.5 LTS with Firefox 31 Release. [bugday-20140804]
Keywords: dev-doc-needed
Version: 31 Branch → Trunk
I am not sure, whether this is a valid bug: "which" was introduced by Microsoft (IE specific quirk) and is to this day not an official web standard (or standardized for that matter) or even properly documented. Firefox simply mimics the original culprits behavior perfectly: IE also has which = 1 on mouseover. In other words, the correct implementation of this feature/bug can be seen in both IE and Firefox and Chrome is the one that differs from the rest. I believe we can close this. For anyone else looking into mouseevents, I recommend taking a look at button or the more complex (and accurate) buttons instead. If you use jQuery, use its event object, as it ensures identical behavior on all browsers!
Since the docs were updated, it's ok to close it for me.
From what I see the 'button' property cannot be used either - it is always 0 (and even if it would work, there is no way to express no button pressed with it). The only thing that does work in Mozilla now is 'buttons' which is not widely supported. jQuery does not solve this either as it only normalizes 'which' (for old IE, I guess, since it treats 'button' as a bitmap): https://github.com/jquery/jquery/blob/master/src/event.js var button = original.button; // Add which for click: 1 === left; 2 === middle; 3 === right // Note: button is not normalized, so don't use it if ( !event.which && button !== undefined ) event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) ); Here is something that works for me: var buttons = e.buttons !== undefined ? e.buttons : e.which === 0 ? 0 : 1 << (e.which - 1);
Priority: -- → P5
Webcompat Priority: --- → ?
Webcompat Priority: ? → P2
Severity: normal → S3

I wonder if Webcompat Priority P2 is still the right rating. https://github.com/webcompat/web-bugs/issues/69919 seems working fine for me now. Are there other webcompat reports?

FWIW, this feature is no longer recommended.

Flags: needinfo?(dschubert)

I re-tested the site, and indeed, they changed their layout and no longer has an issue. Unsetting webcompat-priority as we don't know about any site breakage for this.

Webcompat Priority: P2 → ---
Flags: needinfo?(dschubert)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: