Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect "long press" on touch devices

Tags:

javascript

I'm using contextmenu event to capture right clicks. On touch devices that event fired via "long press".

The problem I'm experiencing is that the contextmenu event doesn't fire on touch devices until touch is released. I could listen for touchstart/mousedown events and set timeout, but it won't be accurate since each device might have its own delay for long press activation.

So, is there a way accurately detect when long press is activated on touch screen devices? (On some devices there is haptic feedback when long press was activated)

like image 991
vanowm Avatar asked Oct 18 '25 06:10

vanowm


1 Answers

As discussed in the comment section.

On most devices contextmenu fires without releasing the touch, so in most cases it should be fine to use the contextmenu event to get the desired result.

This might be a bug in the DevTools of Chromium, since you tested with that. I recommend to simply use the contextmenu event.

In case the specific device really fires the context menu on touch release, the user expects the same behavior on your website/app, so it should be fine to go this route.

like image 167
Martin Braun Avatar answered Oct 19 '25 20:10

Martin Braun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!