Get Selected Text

Last post 04-03-2014, 11:44 AM by jeff330ci. 2 replies.
Sort Posts: Previous Next
  •  04-03-2014, 4:54 AM 80202

    Get Selected Text

    In client-side script I need to get the selected text. Here is what I have tried.

     

    1. var selectionType = editor.GetSelectionType()

    2. if (selectionType == 'Range') {

    3.     var selectedRangeText = editor.SelectContent(editor.GetPointNode());

    4.   }

     

    Line 3 fails with selectedRangeText is 'undefined';

     

    What do I need to get the text, and only the text , that is selected?

     

    Thanks. 

     

  •  04-03-2014, 9:23 AM 80206 in reply to 80202

    Re: Get Selected Text

    Hi jeff330ci,

     

    Please try the way below.

     

    1. <%@ Page Language="c#" ValidateRequest="false" %>  
    2.   
    3. <%@ Register TagPrefix="RTE" Namespace="RTE" Assembly="RichTextEditor" %>  
    4.   
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    6. <html xmlns="http://www.w3.org/1999/xhtml">  
    7. <head>  
    8.   
    9. </head>  
    10. <body>  
    11.     <form id="Form1" method="post" runat="server">  
    12.         <RTE:Editor ID="Editor1" runat="server" />  
    13.         <input type="button" value="get select content" onclick="getSelectContent()" />  
    14.     </form>  
    15. </body>  
    16. </html>  
    17. <script type="text/javascript">  
    18.     function getSelectContent() {  
    19.         var editor1 = document.getElementById('<%= Editor1.ClientID%>').editor;  
    20.         //get select html  
    21.         var selhtml = editor1.ExtractRangeHTML();  
    22.         //get plain text  
    23.         var plainText = jsml.html_decode(selhtml);  
    24.         alert(plainText);  
    25.     }  
    26.   
    27. </script>  
     

    Regards,

     

    Ken 

  •  04-03-2014, 11:44 AM 80209 in reply to 80206

    Re: Get Selected Text

    That is exactly what I was looking for. Thanks!
View as RSS news feed in XML