CKEditor - 使用数据处理器删除脚本标记 [英] CKEditor - remove script tag with data processor
本文介绍了CKEditor - 使用数据处理器删除脚本标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对CKEditor很新(2天前开始使用它),我仍在使用一些配置,例如从编辑器中删除标签。
I am quite new with CKEditor (starting to use it 2 days ago) and I am still fighting with some configuration like removing the tag from editor.
所以对于例如,如果用户在源模式下键入以下内容:
So for example, if a user type in source mode the following:
<script type="text/javascript">alert('hello');</script>
我想将其删除。
查看文档,我发现可以使用HTML过滤器完成此操作。我如此定义它但不起作用。
Looking the documentation, I found that this can be done using an HTML filter. I so defined it but it does not work.
var editor = ev.editor;
var dataProcessor = editor.dataProcessor;
var htmlFilter = dataProcessor && dataProcessor.htmlFilter;
htmlFilter.addRules(
{
elements :
{
script : function(element)
{
alert('Found script :' + element.name);
element.remove();
},
img : function( element )
{
alert('Found script :' + element.name);
if ( !element.attributes.alt )
element.attributes.alt = 'Cookingfactory';
}
}
});
img部分运行良好,但不是脚本1。我想我错过了什么。它甚至不显示脚本的警告信息。
The img part is working well but not the script one. I guess I missed something. It even does not display the alert message for script.
任何帮助都是非常受欢迎的:o)
Any help would be more than welcome :o)
推荐答案
你可以使用这个:
CKEDITOR.replace('editor1', {
on: {
pluginsLoaded: function(event) {
event.editor.dataProcessor.dataFilter.addRules({
elements: {
script: function(element) {
return false;
}
}
});
}
}
});
这篇关于CKEditor - 使用数据处理器删除脚本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文