I have this code, which works for disabling the context menu from appearing after right clicking an element:
function disableRightClick(e) {
e.preventDefault();
}
elem.addEventListener("contextmenu", disableRightClick);
This works on desktop, but on mobile it causes an unfortunate haptic feedback slight vibration after tapping and holding for a few hundred milliseconds on mobile.
How can I get rid of this slight vibration? I tried adding user-select: none
to the element, touch-action: none
, etc. but nothing seems to work.
If I remove the disableRightClick
callback, the phone no longer vibrates when tapping. I suppose I could detect if it was a desktop device somehow (screen width?), and only add the disableRightClick
conditionally, but that seems like a bad solution