Aydın Kara
Top achievements
Rank 1
Aydın Kara
asked on 16 Feb 2009, 03:59 PM
Hi,
When I paste some text from Word to Rad Editor, I want to strip style tags like <h1>.
The html of the text that paste from word is:
<h1>Something</h1>
But I dont want these <h1>, <h2> etc. tags.
How can I do this?
PS: I'm using latest version of RAD Controls for ASP.NET.
When I paste some text from Word to Rad Editor, I want to strip style tags like <h1>.
The html of the text that paste from word is:
<h1>Something</h1>
But I dont want these <h1>, <h2> etc. tags.
How can I do this?
PS: I'm using latest version of RAD Controls for ASP.NET.
3 Answers, 1 is accepted
0
Hi Hasan,
In the upcoming Q1 2009 "Futures" release of RadControls for ASP.NET AJAX, the OnClientPasteHtml event of RadEditor that will be fired when the onpaste event is executed. This will allow the developer to modify / clean only the pasted, but not the whole content inside the editor. You can use this event and write your own code that will strip the <heading> tags when the user paste content in the editor.
Here is a sample example that demonstrates how to attach to the Paste command:
<script type="text/javascript">
function OnClientPasteHtml(sender, args)
{
var commandName = args.get_commandName();
var value = args.get_value(); //this is the pasted content
if (commandName == "Paste")
{
alert("original pasted content: " + value);
var newContent = "modified content"; //write here a regular expression that will strip the <h1>, <h2>, <h3>, etc tags
alert("modified pasted content" + newContent);
args.set_value(newContent); //insert the modified content in the editor
}
}
</script>
<telerik:RadEditor runat="server"
OnClientPasteHtml="OnClientPasteHtml"
ImageManager-ViewPaths="~/"
ID="RadEditor1">
</telerik:RadEditor>
The onpaste event will be executed only when the StripFormattingOptions property is not set to NoneSupressCleanMessage, because then the editor does not execute any code to handle the pasted content and it is pasted without modifications by the browser itself.
Since RadEditor Classic does not offer the OnClientPasteHtml event you can strip the heading tags on submit by attaching to the OnClientSubmit event and firing a regular expression or DOM strip filter.
I would also recommend that you upgrade your project to the new and better RadEditor for ASP.NET AJAX, because it is faster, provides multiple new features and enhancements as well as multiple bug fixes. If you decide to upgrade to the new editor you can find guidance in the following help article: Migration from RadEditor Classic to RadEditor for ASP.NET AJAX.
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
In the upcoming Q1 2009 "Futures" release of RadControls for ASP.NET AJAX, the OnClientPasteHtml event of RadEditor that will be fired when the onpaste event is executed. This will allow the developer to modify / clean only the pasted, but not the whole content inside the editor. You can use this event and write your own code that will strip the <heading> tags when the user paste content in the editor.
Here is a sample example that demonstrates how to attach to the Paste command:
<script type="text/javascript">
function OnClientPasteHtml(sender, args)
{
var commandName = args.get_commandName();
var value = args.get_value(); //this is the pasted content
if (commandName == "Paste")
{
alert("original pasted content: " + value);
var newContent = "modified content"; //write here a regular expression that will strip the <h1>, <h2>, <h3>, etc tags
alert("modified pasted content" + newContent);
args.set_value(newContent); //insert the modified content in the editor
}
}
</script>
<telerik:RadEditor runat="server"
OnClientPasteHtml="OnClientPasteHtml"
ImageManager-ViewPaths="~/"
ID="RadEditor1">
</telerik:RadEditor>
The onpaste event will be executed only when the StripFormattingOptions property is not set to NoneSupressCleanMessage, because then the editor does not execute any code to handle the pasted content and it is pasted without modifications by the browser itself.
Since RadEditor Classic does not offer the OnClientPasteHtml event you can strip the heading tags on submit by attaching to the OnClientSubmit event and firing a regular expression or DOM strip filter.
I would also recommend that you upgrade your project to the new and better RadEditor for ASP.NET AJAX, because it is faster, provides multiple new features and enhancements as well as multiple bug fixes. If you decide to upgrade to the new editor you can find guidance in the following help article: Migration from RadEditor Classic to RadEditor for ASP.NET AJAX.
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Aydın Kara
Top achievements
Rank 1
answered on 20 Feb 2009, 10:34 AM
Hi,
Thanks for the advice. I applied the sample javascript code to our project. But unfortunately this method is not called when a text is pasted by "ctrl+v" or paste from context menu or paste from toolbar. It is called when I did "Paste From Word". So I modified the if statement in the javascript as "if (commandName == "PasteFromWord")". In this case it didnt apply "StripFormattingOnPaste" actions which are "MSWordRemoveAll" and "Css".
How can I fix these new situations? Can you give the expected release date of Q1 2009?
Thanks.
Thanks for the advice. I applied the sample javascript code to our project. But unfortunately this method is not called when a text is pasted by "ctrl+v" or paste from context menu or paste from toolbar. It is called when I did "Paste From Word". So I modified the if statement in the javascript as "if (commandName == "PasteFromWord")". In this case it didnt apply "StripFormattingOnPaste" actions which are "MSWordRemoveAll" and "Css".
How can I fix these new situations? Can you give the expected release date of Q1 2009?
Thanks.
0
Hi Hasan,
We released the Futures build of RadControls for ASP.NET AJAX on Friday and you can download the product from your Client.net account and after that test the provided code in my earlier reply.
The official release is scheduled for 10th of March 2009.
All the best,
Rumen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
We released the Futures build of RadControls for ASP.NET AJAX on Friday and you can download the product from your Client.net account and after that test the provided code in my earlier reply.
The official release is scheduled for 10th of March 2009.
All the best,
Rumen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.