关于前端安全性
比如说我们的头像,昵称这些都可能会被用户恶意注入js代码,进行恶意破坏,我们可以对这些操作预防。
js 对于代码进行转移从而防止恶意注入
function escapeString(value) { value = value + ""; var RexStr = /\</g; var step1 = value.replace(RexStr, '<'); var RexStr2 = /\>/g; var step2 = step1.replace(RexStr2, '>'); var RexStr3 = /\"/g; var step3 = step2.replace(RexStr3, '"'); var RexStr4 = /\'/g; var step4 = step3.replace(RexStr4, '''); return step4; }
如果是用的velocity模板的话可以使用$escapeTool.html()来处理比较方便