onclientPasteHTML

4 posts, 0 answers
  1. Régis Giudicelli
    Régis Giudicelli avatar
    11 posts
    Member since:
    Oct 2006

    Posted 30 Oct 2008 Link to this post

    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
  2. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 04 Nov 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Régis Giudicelli
    Régis Giudicelli avatar
    11 posts
    Member since:
    Oct 2006

    Posted 04 Nov 2008 Link to this post

    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 ?
  5. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 07 Nov 2008 Link to this post

    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.
Back to Top