1

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Naeco
  • 133
  • 1
  • 1
  • 9

2 Answers2

2

It is not a "mobile event", it is a good old contextmenu event who are fired :

https://developer.mozilla.org/fr/docs/Web/API/Element/contextmenu_event

I have finally found the answer here : Weird behavior of long presses in Chrome and Firefox for Android

Naeco
  • 133
  • 1
  • 1
  • 9
2

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));
DevAb
  • 530
  • 6
  • 12