Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.71 KB

strip-html-on-paste.md

File metadata and controls

47 lines (35 loc) · 1.71 KB
title page_title description slug tags published position
Strip HTML on Paste
Strip HTML on Paste - RadEditor
Check our Web Forms article about This is a custom solution for stripping some HTML when pasting in RadEditor.
editor/how-to/strip-html-on-paste
custom, solution, paste, strip, HTML, editor, content area
true
7

Strip HTML on Paste

This help article shows how to strip HTML tags from content that is pasted in RadEditor.

Follow these steps:

  1. Handle the [OnClientPasteHtml event]({%slug editor/client-side-programming/events/onclientpastehtml%}).
  2. Catch the Paste command.
  3. Obtain the content via the get_value() method of the event arguments and modify it as needed.
  4. Set the modified content via the set_value() method of the event arguments.

caption Example 1: Stripping <strong>, <em> and <span> tags on paste in RadEditor.

<telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml" />

<script>
    function OnClientPasteHtml(editor, args) {
        var commandName = args.get_commandName();

        // Paste command is the one that handles plain paste, e.g., when Ctrl+V is used.
        if (commandName === "Paste") {
            var htmlToBePasted = args.get_value(); // Get the value to be pasted
            
            // Use Regex to strip <strong>, <em> and <span> tags.
            htmlToBePasted = htmlToBePasted.replace(/<(\/)*(strong|em|span)[^>]*>/gi, "");

            // Set the processed content to the arguments.
            args.set_value(htmlToBePasted);
        }
    }
</script>

See Also

  • [OnClientPasteHtml event]({%slug editor/client-side-programming/events/onclientpastehtml%})