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?
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?
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);
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.