JavaScript 关于显示从 kindeditor 中保存的内容到页面

d4rkl0rd · February 16, 2012 · Last by rubychinatest replied at August 10, 2013 · 6549 hits

后台新闻用 kindeditor 作为富文本框保存的内容到表中,前台我取出来直接 <%=@content%> 显示,结果什么
 等标记都直接显示出来了,请问下,这里需要进行转换吗?在 JAVA 中,是可以直接取出来显示,没问题的,就不知道 RAILS 如何做了。

<%=raw @content %>

其实是为了安全起见,Rails 会自动把 html 的代码转义,避免不安全的 html 代码。要按 html 显示,你就按一楼的做法就可以了。

<%= raw @content %>

刚用到这个,很有用,顶!

使用 kindeditor 保存内容,注意服务器端还要对内容做验证,否则使用 raw 显示内容时会有 xss 威胁。

You need to Sign in before reply, if you don't have an account, please Sign up first.