I've configured Pointer Events through pointerevents-polyfill.
There's an issue I have where I cannot differentiate between left- and right-clicks where right-clicking a nav item will do the same action as left-clicking instead of opening the right-click menu.
The specific event I'm using is pointerup.
Is there a way with Pointer Events to check if the event is a left- or right-click?
I've configured Pointer Events through pointerevents-polyfill.
There's an issue I have where I cannot differentiate between left- and right-clicks where right-clicking a nav item will do the same action as left-clicking instead of opening the right-click menu.
The specific event I'm using is pointerup.
Is there a way with Pointer Events to check if the event is a left- or right-click?
Share Improve this question asked Feb 6, 2014 at 18:04 Kevin GhadyaniKevin Ghadyani 7,2978 gold badges47 silver badges66 bronze badges3 Answers
Reset to default 8Looks like there is a property called button that has a value of 0 if it's the primary pointer (left mouse button).
I haven't used this library but from looking at the source and the W3C spec it would appear that way.
You can always print/debug the event and see what the property is.
The following code identifies “main button” type pointer events like left mouse click, touch.
if(e.pointerType !== 'mouse' || e.button === 0){
//Not mouse pointer or mouse pointer with left button
}
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
- 0: Main button pressed, usually the left button or the un-initialized state
- 1: Auxiliary button pressed, usually the wheel button or the middle button (if present)
- 2: Secondary button pressed, usually the right button
- 3: Fourth button, typically the Browser Back button
- 4: Fifth button, typically the Browser Forward button
I used event.type == 'click' (left) vs. event.type == 'contextmenu' (right).