Javascript String encodeHTML()
define(function() { String.prototype.encodeHTML=function () { var encodeHTMLRules, matchHTML; encodeHTMLRules = {/*from ww w . jav a2 s .c om*/ "&": "&", "<": "<", ">": ">", '"': '"', "'": ''', "/": '/' }; matchHTML = /&(?!#?w+;)|<|>|"|'|\//g; return this.replace(matchHTML, function(m) { return encodeHTMLRules[m] || m; }); };