0

Is it possible to get X and Y position of the highlighted text by your mouse on the current active web page and if so how ?

Any links and advises how to achieve that with jQuery?

j08691
  • 197,815
  • 30
  • 248
  • 265
Venelin
  • 2,507
  • 3
  • 42
  • 90

2 Answers2

0

You can check this Javascript library rangeblock.

You can locate, measure, and represent layouts of text ranges.

Example

// TypeScript
import * as rb from "rangeblock"

// measure layouts
let block = rb.extractSelectedBlock(window, document);
if (!block) {
    console.error("please select some text on the web page");
    return;
}
console.info("Text layout: " + JSON.stringify(block.dimensions));

// representation of the text range 
console.info("Text layout: " + JSON.stringify(block.rangeMeta));

// recreate range using RangeMeta
let meta :RangeMeta = ... ; 
block = rb.restoreBlock(window, document, meta);
Julian
  • 30,223
  • 19
  • 105
  • 147
-1

If you don't need IE9:

s = window.getSelection();

Returns a Selection. So try

s = window.getSelection();
oRange = s.getRangeAt(0); //get the text range
oRect = oRange.getBoundingClientRect(); 

oRect will be the bounding rectangle in client (fixed) coordinates.

From this answer here.

Tyler Morrow
  • 939
  • 8
  • 31