Is there an event for situations where something is selected on an HTML page like arbitrary text within a span element? Does such a thing exist or does one need to poll at regular interval & analyze the window.getSelection() ?
I would like to trap this event type from within a browser extension (Chrome).
New York Times implements some "on selection" type of functionality on all their articles without monitoring for a specific "onselection" event. Example here, highlight some text and you'll see a "?" pop up that you can use for search.
Here's the relevant code. Basically looks like onmouseup of any body text, they get the document (or window) selection and use that.
The existing "onselect" event is spec'd to only apply to input and textarea elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With