JavaScript function not working in IE10

2 posts, 0 answers
  1. Shweta
    Shweta avatar
    6 posts
    Member since:
    Apr 2014

    Posted 15 May 2014 Link to this post

    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?

  2. Nikolay
    Admin
    Nikolay avatar
    64 posts

    Posted 19 May 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top