URGENT: RAD Editor,how to prevent pasting certain formattings.

2 posts, 0 answers
  1. Sachidananda
    Sachidananda avatar
    12 posts
    Member since:
    Jun 2011

    Posted 29 Aug 2011 Link to this post

    Hi,

    Assume end user is trying to copy content from MS word and pasting into rad editor.

    When he Right clicks and choose From MS word or use Ctrl+V , how to prevent him from copying

    1.Any inserted files or any other objects from MS Word.
    2.Tables in MS Word
    3.Forecolor/backcolor information
    4.Any hyperlinks

    But he should be able to copy
    1.Text with Fonts specific to what can be chosen from the RAD editor dropdown.
    2.Text with Font size specific to what can be chosen from the RAD editor dropdown.
    3.Normal formatting like Bold/Italic/Underline,alignment,bulleting etc.

    Please help with this as this is very urgent.

    Thank you.



  2. Rumen
    Admin
    Rumen avatar
    13755 posts

    Posted 30 Aug 2011 Link to this post

    Hi Sachidananda,

    RadEditor does not offer the requested stripping functionality out-of-the box and for the time being we do not plan to provide such.

    What you can do is to attach to the OnClientPasteHtml event of RadEditor, obtain the pasted content, strip the unwanted tags and formatting and insert the modified content in the content area:

    <script type="text/javascript">
    function OnClientPasteHtml(sender, args) {
    var commandName = args.get_commandName();
      var value = args.get_value();
      if (commandName == "Paste")
      {
         alert(value);
         //add below regular expressions that will strip the undesired tags, attributes, etc
         value = value.replace(/\<p[^\>]*>/gi, "<br/>").replace(/\<\/p>/gi, "");
          alert(value);
         args.set_value(value); //set the modified pasted content in the editor
      }
    }
    </script>
    <telerik:RadEditor ID="RadEditor1" runat="server" OnClientPasteHtml="OnClientPasteHtml">
    <content></content>
    </telerik:RadEditor>


    All the best,
    Rumen
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top