To get the text selection in Javascript you can use the following snippet.
Sample Javascript
function GetTextSelection() { return (!!document.getSelection) ? document.getSelection() : (!!window.getSelection) ? window.getSelection() : document.selection.createRange().text; }