Reputation: 133
On Android Chrome, when selecting a text by long press, the events "touchend" and "touchstart" are not triggered. The following solutions therefore do not work:
How to detect a long touch pressure with javascript for android and iphone?
Which event is triggered?
The "onselect" event seems to work only in inputs or textarea.
Upvotes: 1
Views: 2258
Reputation: 133
It is not a "mobile event", it is a good old contextmenu
event that is fired:
https://developer.mozilla.org/en/docs/Web/API/Element/contextmenu_event
I have finally found the answer here: Weird behavior of long presses in Chrome and Firefox for Android
Upvotes: 2
Reputation: 598
The "selectionchange" event is working for : Android (Chrome) and iOS (Safari).
The "contextmenu" event is working for : Android (Chrome, Mozilla and Opera).
For Mozilla and Opera you might need to wrap your function with a setTimeout:
document.addEventListener('contextmenu', setTimeout(handleSelection, 1));
Upvotes: 3