Following scenario: When selecting text on iOS Safari (lets assume a "normal" html page) an blue overlay occurs, indicating that you have selected a specific passage. Furthermore, you are able to change that selection, in order to correct your initial selection area. I'm interested in capturing exactly that event, when selection area change is done. Is it possible (when yes, how?) to catch such an event within Javascript? Thx in advance.
Asked
Active
Viewed 7,678 times
2 Answers
18
Mobile Safari supports the selectionchange
event, which fires on Document
nodes:
document.addEventListener("selectionchange", function() {
alert("Selection changed!");
}, false);

Tim Down
- 318,141
- 75
- 454
- 536
-
Thank you. selectionchange did the trick! Unfortunately, it does not carry any information about the selection itself, right? When inspecting touchend event for instance, I can find helpful information about x/y coordinates or selection range. – Marco Dec 20 '12 at 16:33
-
3@Marco: The selection is accessible via `window.getSelection()` and is updated by the time `selectionchange` fires. – Tim Down Dec 20 '12 at 16:49
3
I've found that this event fires multiple times even on a single word selection (with a tap), and of course it fires when you drag the selection handles ...
I created a small workaround to get only the text selection end event.
you can see it here: End of text selection event?
or in a small post on my blog: http://www.dimshik.com/end-of-text-selection-event-on-ios-workaround/