javascript CKEditor 4.2.2 - allowedContent = true 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19967092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CKEditor 4.2.2 - allowedContent = true is not working
提问by Pierre
I guess I've read most of the SO questions and CKEditor documentation about this, but it does not work for me.
我想我已经阅读了大部分关于此的 SO 问题和 CKEditor 文档,但它对我不起作用。
It should be plain and simple, in my CKEditor config.js, I have this :
它应该简单明了,在我的 CKEditor config.js 中,我有这个:
CKEDITOR.editorConfig = function(config) {
config.allowedContent = true;
};
But the html is still filtered and this piece of code is being stripped :
但是 html 仍然被过滤,这段代码正在被剥离:
<p>
<a href="/site/public/press.pdf"><span class="icon-presseFile"></span></a>
<a href="/site/public/pics.zip"><span class="icon-pressePics"></span></a>
</p>
into this :
进入这个:
<p> </p>
The <span>
elements are font icons.
的<span>
元素是字体的图标。
Any help would be greatly appreciated.
任何帮助将不胜感激。
EDITIt works if I add some text in the <span>
elements (but I don't want tohave to do that)
编辑如果我在<span>
元素中添加一些文本,它就可以工作(但我不想这样做)
回答by Will Henderson
I found that I had to add it OUTSIDE of the main config function.
我发现我必须在主配置功能之外添加它。
This worked:
这有效:
CKEDITOR.editorConfig = function( config ) {
...
};
CKEDITOR.config.allowedContent = true;
But this didn't:
但这并没有:
CKEDITOR.editorConfig = function( config ) {
config.allowedContent = true;
...
};
回答by valME.io
Be aware that it might be a rogue plugin causing config.allowedContent = true to be ignored. I just learned this at a cost of 12 hours of my life.
请注意,它可能是一个流氓插件,导致 config.allowedContent = true 被忽略。我只是以我生命中的 12 小时为代价学会了这一点。
The offending plugin overrode config.allowedContent = true in the custom config file. So if you're banging your head against the wall cursing at CKEditor, try disabling/commenting out all of your plugins (config.extraPlugins). If the problem goes away, you know one of those plugins is the cause.
违规插件覆盖了自定义配置文件中的 config.allowedContent = true 。因此,如果您在 CKEditor 上用头撞墙诅咒,请尝试禁用/注释掉所有插件(config.extraPlugins)。如果问题消失,您就会知道其中一个插件是原因。
回答by Pierre
This solution helped me solved my problem : CKEditor strips <i> Tag
这个解决方案帮助我解决了我的问题:CKEditor strips <i> Tag
For the span I wrote in the config.js :
对于我在 config.js 中写的跨度:
// ALLOW <span></span>
config.protectedSource.push( /<span[\s\S]*?\>/g ); //allows beginning <span> tag
config.protectedSource.push( /<\/span[\s\S]*?\>/g ); //allows ending </span> tag
回答by bets
I had the same problem using Firefox. To solve it I had to change the name of the config.js file to anything else like ckeConfig.js and declare the new name:
我在使用 Firefox 时遇到了同样的问题。为了解决这个问题,我必须将 config.js 文件的名称更改为其他任何名称,例如 ckeConfig.js 并声明新名称:
CKEDITOR.replace("textAreaId", {
customConfig: 'yourPath/ckeditor/ckeConfig.js',
});
And don't forget to link in Html too:
也不要忘记在 Html 中链接:
<script src="~/yourPath/ckeditor/ckeditor.js"></script>
<script src="~/yourPath/ckeditor/ckeConfig.js"></script>
回答by KennethDale1
Try this:
CKEDITOR.replace('instanceName', { extraAllowedContent: 'a span' });
试试这个:
CKEDITOR.replace('instanceName', { extraAllowedContent: 'a span' });
You can put whatever tags in that extraAllowedContent string that you do not want it to alter.
您可以在 extraAllowedContent 字符串中放置您不希望它更改的任何标签。