samedi 30 juillet 2016

Select the text below the pointer

Does anyone know if it's possible to obtain the text that the mouse pointer is over in a web page?

Some assumptions can be made:

  1. The web page will contain only text, no images. Minimal styling.
  2. The content is all from the same domain, no CORs or iFrames involved.
  3. JavaScript events can be applied anywhere, to any element, as needed to make this work.
  4. Use of 3rd party client side libs is fine. No server side libs.
  5. Use of 'modern' browser APIs is fine, but ideally we can support back to IE9 (no earlier needed)

I'm aware of the Selection API, which allows you to return the selected text. But this is almost the opposite of that: A way to track the pointer, and obtain whatever content it passes over, ideally down to a single word basis, and then select it via code.

I can think of ways to achieve this by rendering the text to a canvas, then tracking pointer movement across the canvas, but I was hoping to find a more 'normal' approach.




Aucun commentaire:

Enregistrer un commentaire