Javascript get highlighted selected text

function getSelText(){
    if (window.getSelection)  {
        return window.getSelection();
    } else if (document.getSelection)   {
        return document.getSelection();
    } else if (document.selection)   {
        return document.selection.createRange().text;
    }

    return "";
}