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

Pasting HTML into the Editor

4 Answers 182 Views
Editor
This is a migrated thread and some comments may be shown as answers.
CS
Top achievements
Rank 1
CS asked on 09 Apr 2008, 07:20 PM
Hello,
I am trying to paste HTML into the RadEditor in Design Mode using javascript by clicking a button outside the editor .

When I just call the editor's pasteHtml method , the html is always inserted at the beginning of the editor.  To get the html to paste into the last cursor position I am using the code shown below.  The problem is that when I call restorePoint.select(), all contents of the editor are selected and replaced instead of the html being placed at the previous cursor position.  Any help is appreciated.

This function fires on the editor's OnClientLoad event:

function EditorOnClientLoad()

{

var editor = $find(EditorID);

var element = document.all ? editor.get_document().body : editor.get_document();

$telerik.addExternalHandler(element,

"blur", function(e)

{

restorePoint = editor.createRestorePoint();

}

);

}


This is the code that's called when pasting the html:

restorePoint.select();

$find(EditorID).pasteHtml(html);







Thanks,
Craig

4 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 10 Apr 2008, 11:56 AM
Hi Craig,

I tried to reproduce the reported problem with the following code

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<telerik:radeditor runat="server" ID="RadEditor1"></telerik:radeditor>
<input type="button" value="Paste Content" onclick="InsertSpan();return false;" />
<script type="text/javascript">
function InsertSpan()
{                 
  var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to the editor
  editor.pasteHtml('<span style="width:100px;border: 1px solid red;background-color: blue;color: white;">sample content</span>');
}
</script> 

taken from this help article: pasteHtml but I was not able to reproduce the problem. I was able to paste content at cursor position.

Could you please test this code and tell me whether are you able to paste at cursor position? If you are able to reproduce the problem please provide steps how to reproduce it.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
CS
Top achievements
Rank 1
answered on 10 Apr 2008, 03:46 PM
Thank you for the quick reply. 

Yes, the code you sent me does work.  I've determined that the cause of the problem is the button that I am using.  It's another third-party control.  When I use the standard html input button or use the ASP.Net button control to fire the pasting of the html it works, but if I use the third-party button control it always pastes at the beginning of the editor, even though I am executing the same code to do the paste.  I will replace my third party control with a standard control.

Thanks,
Craig
0
Rumen
Telerik team
answered on 10 Apr 2008, 04:25 PM
Hi Craig,

We do not support third party control, however in your scenario it is possible that the third party button is taking the focus and that is why the content is pasted at the beginning of the content area.

What I would suggest is to set programmatically the unselectable="on" attribute to this custom button, which most likely will fix the problem. This attribute will make the button html unselectable and it will not get focus when clicked.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
A
Top achievements
Rank 1
answered on 20 Feb 2009, 08:11 PM
I had a similar issue where the cursor kept going to the beginning of the editor. The unselectable="on" attribute fixed the problem!
Tags
Editor
Asked by
CS
Top achievements
Rank 1
Answers by
Rumen
Telerik team
CS
Top achievements
Rank 1
A
Top achievements
Rank 1
Share this question
or