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

JavaScript function not working in IE10

1 Answer 64 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Shweta
Top achievements
Rank 1
Shweta asked on 15 May 2014, 12:38 PM
Hi,

I am using below javascript function to add some text in RadEditor on click of a button.

function TestFunction()
{
      var editor = $find("<%= EditorID.ClientID %>");
      editor.pasteHtml("Test");
}

I want the text to be added at the current position of cursor in editor.In chrome and mozilla it is working fine. but for IE it is adding the text at the start of editor.
Does anyone know how to resolve this problem with IE?

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 19 May 2014, 11:32 AM
Hello,

You can handle RadEditor's selectionChange event and save current cursor position. Then restore it before pasting the content. Here is an example: 
<telerik:RadEditor ID="RadEditor1" Runat="server" OnClientSelectionChange="OnClientSelectionChange">
    <Content>
        <p>line 1</p>
        <p>line 2</p>
        <p>line 3</p>
    </Content>
</telerik:RadEditor>
 
<telerik:RadButton ID="RadButton" runat="server" Text="paste content" OnClientClicking="OnClientClicking"></telerik:RadButton>
 
<script>
    var range;
 
    function OnClientSelectionChange(editor, args) {
        range = editor.getSelection().getRange(true);
    }
 
    function OnClientClicking(button, args) {
        var editor = $find("<%=RadEditor1.ClientID%>");
        if (range) {
            editor.getSelection().selectRange(range);
        }
        editor.pasteHtml("<strong>new content</strong>");
        args.set_cancel(true);
    }
</script>

You can see how it behaves in this screencast.

If this does not help, please provide a sample page with the scenario.

Regards,
Nikolay
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Editor
Asked by
Shweta
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or