This is a migrated thread and some comments may be shown as answers.

Cursor position after set_html(content); is called from Javascript

1 Answer 89 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Brian Garson
Top achievements
Rank 2
Brian Garson asked on 07 Jun 2011, 07:24 PM
Hello,

I'm trying to sort out a way to avoid having the cursor at position 0 in the editor after using the editor.set_html("I added some text"); function from javascript.  It seems in  when set_html is used your cursor automatically moves to position 0. You can see from your example on your site by clicking set_html http://mono.telerik.com/Editor/Examples/ClientsideAPI/DefaultCS.aspx 

Is there any workaround for this?  In short what I'm trying to accomplish is to Filter the contents of the editor and replace that content, via JavaScript.

thanks,

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Jun 2011, 11:59 AM
Hi Brian,

You can set the cursor to the end of the content after using the set_html() method using the code below:

<telerik:radeditor runat="server" ID="RadEditor1">
   <Content>
       Here is sample content!
   </Content>
</telerik:radeditor>
<input type="button" value="reset" onclick="ResetContent();return false;" />
<script type="text/javascript">
    function ResetContent() {
        var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to RadEditor client object
        editor.set_html("test"); //reset the content
        var doc = editor.get_document();
        doc.execCommand("SelectAll", null, false);
        editor.getSelection().collapse(); 
    }
</script>



All the best,
Rumen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Editor
Asked by
Brian Garson
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Share this question
or