admin管理员组文章数量:1401968
There is a problem with CKEditor when the user inserts empty tags:
(in HTML source mode)
<a href="fds" class="doIt"></a>
When he presses on the source and then back again, the tag 'A' is gone. I made a little research, and I found that this happens since there is a very plicated function in ckeditor.js that checks whether there is a value inside the element. If there's none the CKEditor drops the tag.
There is a problem with CKEditor when the user inserts empty tags:
(in HTML source mode)
<a href="fds" class="doIt"></a>
When he presses on the source and then back again, the tag 'A' is gone. I made a little research, and I found that this happens since there is a very plicated function in ckeditor.js that checks whether there is a value inside the element. If there's none the CKEditor drops the tag.
Share Improve this question edited Feb 27, 2020 at 18:01 Nmk 1,3192 gold badges14 silver badges28 bronze badges asked Aug 2, 2012 at 16:54 RoyRoy 2433 silver badges10 bronze badges 2- Have you tried removing the function? – Waleed Khan Commented Aug 2, 2012 at 19:09
- This creates havoc with my code, since some of my so-called empty div's actually have background-images, but CKEditor doesn't care, and removes them nonetheless... – Stefan Commented Nov 28, 2018 at 8:46
4 Answers
Reset to default 1I know this is old, but in CKEDITOR 4.x you can do:
CKEDITOR.dtd.$removeEmpty.ElementHere = 0;
Replace ElementHere with whatever tag you want. Like allowing empty i tags for icons:
CKEDITOR.dtd.$removeEmpty.i = 0;
If it doesn't affect anything try adding
in your A tag. ckeditor validates, sanitizes, and cleans html. Obviously it doesn't like empty anchor tags.
I found the solution for this specific problem i ran into with the tag
The original answer i got from CKEditor strips <i> Tag
The fix or tweak (you name it) for it is to set the following into the ckeditors config.js:
// ALLOW <i></i>
config.protectedSource.push( /<i[\s\S]*?\>/g ); //allows beginning <i> tag
config.protectedSource.push( /<\/i[\s\S]*?\>/g ); //allows ending </i> tag
Try adding this line into your config.js file:
CKEDITOR.config.allowedContent = true;
Hope this helps
本文标签: javascriptCkeditor removes empty tagsStack Overflow
版权声明:本文标题:javascript - Ckeditor removes empty tags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744251849a2597289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论