Sometimes, we want to detect long press in JavaScript.
In this article, we’ll look at how to detect long press in JavaScript.
How to detect long press in JavaScript?
To detect long press in JavaScript, we can listen for the contextmenu
event.
For instance, we write
document.addEventListener('contextmenu', callback);
to call addEventListener
to listen for the contextmenu
event.
The callback
function is called when when the contextmenu
event is triggered by long presses.
Conclusion
To detect long press in JavaScript, we can listen for the contextmenu
event.