New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Strip HTML on Paste
This help article shows how to strip HTML tags from content that is pasted in RadEditor.
Follow these steps:
- Handle the OnClientPasteHtml event.
- 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.
Example 1: Stripping
<strong>
,<em>
and<span>
tags on paste in RadEditor.
ASP.NET
<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>