2017-10-12 73 views
1

我正在使用ckeditor。 我检查哪些元素是默认不允许运行:Ckeditor disallow img元素

ckEditor.on('instanceReady', function() { 
     console.log(JSON.stringify(ckEditor.filter.allowedContent, null, '\t'));  
    }); 

这表明img元素允许的(尽管在IMG按钮不会出现在我的工具栏)。

因为我不希望用户能够使用img元素提交代码,所以我想完全禁止这样做。初始化编辑时

config.disallowedContent = 'img'; 

和也尝试:

CKEDITOR.replace("comment", { 
     disallowedContent: 'img' 
    }); 

当我显示允许的内容与ckEditor.filter.allowedContent命令时,img元件仍显示为我试图与不允许它在config.js文件允许。

我在做什么错?我认为它仍然有必要禁止img的情况下,有人在编辑器中粘贴代码...

(我也验证服务器端,但理想情况下,服务器端和客户端匹配,即:不允许img)。

感谢

+0

如果您通过配置来替换功能它的工作原理:https://jsfiddle.net/reoh7j74/214/文档指出,最好的办法是在页面定义为:https://docs.ckeditor。 !COM/ckeditor4 /文档/#/引导/ dev_configuration – HMR

+0

也许你需要一个不同版本的CKEditor的,内容过滤器在4.1中引入:https://docs.ckeditor.com/ckeditor4/docs/#!/guide/dev_advanced_content_filter – HMR

+0

嘿,谢谢,我正在运行4.7.3版本。当我运行你的小提琴,并看看什么是允许的:https://jsfiddle.net/bfyuL1cy/,它似乎'img'标签仍然存在。我也不是很了解你的代码。为什么仅仅将'disallowedContent:'img''传入替换函数(没有'disablePlugin ...'代码)是不够的? – theyuv

回答

0

为了禁止图像,请使用以下代码:

CKEDITOR.replace('editor1', { 
    disallowedContent: 'img' 
}); 

请注意,CKEDITOR.instances.editor1.filter.disallowedContentCKEDITOR.instances.editor1.filter.allowedContent是两个单独的列表和添加元素一个不从其他删除它。您可以在allowedContent list中定义(或者编辑器默认为这样做)允许的元素列表以及disallowedContent list中的禁止元素列表。后者优先于前者 - https://docs.ckeditor.com/ckeditor4/docs/#!/guide/dev_disallowed_content。这就是编辑器不允许图像的原因。