User is on a webpage , uses his mouse to select stuff, how can i use javascript to know what has been selected?
2 Answers
To get the raw text currently highlighted on the page you can do something like this:
function getSelectedText() {
return window.getSelection ? window.getSelection()
: document.selection.createRange().text;
}
Check an example of the above code here.
More info: