CKeditor富文本编辑器在浏览器中显示html标签 [英] CKeditor rich text editor displaying html tags in browser

查看:2284
本文介绍了CKeditor富文本编辑器在浏览器中显示html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我正在建设的网站上安装CKeditor富文本WYSIWYG编辑器,它似乎工作正常,除了它插入文本到我的mysql数据库作为编码html而不是常规的html,然后当浏览器输出这个文本,它将编码的数据转换为正常的html,然后显示在显示html标签的浏览器中,没有样式!?



p>

 这是文字


b $ b

到编辑器中,然后插入

 & lt; p& ; / p& 

。然后当页面被调用浏览器转换上述和outout页面上的以下内容:

 < p& ; / p> 

显然我只想要这是文本显示在页面上。



有人知道为什么会发生这种情况/如何解决?





干杯

解决方案

您不想让CKEditor为您创建段落,请设置 config.autoParagraph 更改为false。此外,您可能需要使用 更改输入密钥行为, config.enterMode 设置为 CKEDITOR.ENTER_BR



a href =http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter =nofollow>关于消失的样式 ...



< hr>

编辑:好的,看来我错过了你的观点。



因此,您的网站在显示您输入的内容时会显示HTML标记,而不是HTML?
那么问题是你的服务器端而不是CKEditor。您可以在控制台中验证 CKEDITOR.instances.yourInstance.getData()产生正确的未转义的HTML:

 < p>这是文字< / p> // 对! 

如果是这样,我坚信它是CKEditor的只是罚款,这是你的服务器应用程序即将特殊字符转换为实体(即类似于PHP htmlspecialchars ),同时保存到数据库。你没有提到在那里使用什么样的框架/语言,所以我可以告诉你,这是为了保护用户输入,以防止跨站点脚本,打破布局等,所有流行的框架允许您禁用该功能特定字段。只需参考文档。


I've just installed CKeditor rich text WYSIWYG editor on a site I'm building and it seems to be working ok except for the fact that it inserts text into my mysql database as encoded html rather than regular html and then when the browser outputs this text it converts the encoded data into regular html that then displays in the browser showing the html tags and none of the styling!?

eg I type:

"This is text"

into the editor and it then inserts

&lt;p&gt;This is text&lt;/p&gt;

into the database. Then when the page is called the browser converts the above and outouts the following on the page:

<p>This is text</p>

obviously I just want "This is text" to display on the page.

Does anyone know why this is happening/how to solve it please?

Any suggestions would be most welcome.

Cheers

解决方案

If you don't want CKEditor to create paragraphs for you, set config.autoParagraph to false. Additionally you may want to change enter key behaviour with config.enterMode set to CKEDITOR.ENTER_BR.

And regarding disappearing styles...


EDIT: OK, it seems I missed your point.

So your website is displaying HTML markup instead of HTML while rendering out what you typed? Then the problem is your server side rather than CKEditor. You can verify in your console that CKEDITOR.instances.yourInstance.getData() yields the correct, unescaped HTML:

<p>This is text</p> // Right!

If it is so, and I strongly believe it is, CKEditor's just fine and this is your server app that is converting special chars into entities (i.e. like PHP htmlspecialchars) while saving to database. You didn't mention what kind of framework/language you use there, so I can just tell you that it is to secure user input to prevent cross-site scripting, breaking layouts etc. and all popular frameworks allow you to disable that feature for a particular field. Simply refer to documentation.

这篇关于CKeditor富文本编辑器在浏览器中显示html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆