How to get the selected text from a HTML document using JavaScript?
The use case was quite simple. We had an HTML document where the user was selecting a block of text. We wanted to get that selected text using JavaScript. Following the code segment that does that in JavaScript:
window.getSelection().toString
Source:
Selected text JavaScript