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

onclientPasteHTML

3 Answers 175 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Régis Giudicelli
Top achievements
Rank 1
Régis Giudicelli asked on 30 Oct 2008, 04:42 PM
Hi
When I'm using the "Paste" command, the "onclientPasteHtml" event is not launched. I have to call the PasteAsPlainText or PasteFromWord to make it work, but PasteFromWord automatically add a linefeed before my text is copied. In my function called from the event, I'm doing a PasteHtml("blabla"). I tried to put a space before, like PasteHtml(" blabla") but I still have the line feed.
 
What can I do to launch the onclientPasteHtml event with the Paste command or to use the PasteFromWord command without the line feed ?

Thanx

Régis

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 04 Nov 2008, 08:51 AM
Hi Régis,

You can use the following code to attach to the onpaste event of RadEditor and implement your scenario:

<script type="text/javascript">
function OnClientLoad(editor, args)
{
   var element = document.all ? editor.get_document().body : editor.get_document();
   $telerik.addExternalHandler(element, "paste", function(e)
   {
       alert('You are pasting content in the editor');
       editor.pasteHtml("test");
      
       //cancel the browser's paste event
       if (e.preventDefault) e.preventDefault(); 
       if (e.stopPropagation)e.stopPropagation();
       return false;

   });
}
</script>
<telerik:RadEditor runat="server" StripFormattingOnPaste="noneSupressCleanMessage"
    OnClientLoad="OnClientLoad"
    ID="RadEditor1">
</telerik:RadEditor>

Please, note that the StripFormattingOnPaste or StripFormattingOptions properties should be set to NoneSupressCleanMessage, because in other case the editor will capture the paste event.

You should also note that the paste event is supported only by Internet Explorer and the new Firefox 3.x. Opera and Safari do not expose such event and you cannot capture the paste command and understand whether the user is pasting content.

The version of the Telerik.Web.UI.dll in my project is 2008.3.1031.20, which is Q3  2008 "Futures" build.

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Régis Giudicelli
Top achievements
Rank 1
answered on 04 Nov 2008, 10:39 AM
Hi Rumen
It works, but the question is, in your example, "test" is pasted but how can I paste the clipboard content  ? Knowing that I can't paste the clipboard in the editor and modify the content afterwards, the content is very long and I'd like to analyse only the pasted content. I searched everywhere but it seems that the GetClipboardAsHtml method don't exist on this version. How can I do It ?
0
Rumen
Telerik team
answered on 07 Nov 2008, 09:16 AM
Hi Régis,

The GetClipboardAsHtml method works only in Internet Explorer 6.0 due to browser security restrictions and it is not suitable for your scenario. Firefox does not allow to obtain the clipboard information and you can strip the content once it is pasted in the content area.

For your convenience I created a sample example demonstrating how to strip the pasted images in IE by pasting the content in a hidden DIV, modifying it and after that to paste it in the editor. In Firefox this solution cannot be implemented because the execCommand("Paste") command does not work and you should firstly paste the content in the editor and after that to modify it for example using the FormatStripper tool.

Please, note that this is just an example and Telerik do not support. Feel free to modify and enhance the code to fit your scenario.

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Régis Giudicelli
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Régis Giudicelli
Top achievements
Rank 1
Share this question
or