Does anybody have a cross browser JS function to get selected text

  •  02-08-2008, 7:37 AM

    Does anybody have a cross browser JS function to get selected text

    I am trying to create a cross browser JS function to get selected text ... does anybody have anything better than what I am using?

    function GetSelectedText()
       {
       var retval='';
     
       <%If mozilla Then%>
             sel=ce.GetSelection();
             retval=sel.focusNode.textContent.substr(sel.anchorOffset,sel.focusOffset-sel.anchorOffset);
       <%ElseIf IE Then%>
             sel=ce.GetSelection().createRange();
             retval=sel.htmlText;
       <%End If%>
     
       return retval;
       }
View Complete Thread