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 |
This help article shows how to strip HTML tags from content that is pasted in RadEditor.
Follow these steps:
- Handle the [OnClientPasteHtml event]({%slug editor/client-side-programming/events/onclientpastehtml%}).
- Catch the Paste command.
- Obtain the content via the
get_value()
method of the event arguments and modify it as needed. - 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>
- [OnClientPasteHtml event]({%slug editor/client-side-programming/events/onclientpastehtml%})