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
  • 204,283
  • 31
  • 260
  • 272
Venelin
  • 2,905
  • 7
  • 53
  • 117

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
  • 33,915
  • 22
  • 119
  • 174
-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
  • 949
  • 8
  • 31