List of utility methods to do HTML Escape
htmlEscape()String.prototype.htmlEscape = function (){ var escapedStr = String(this).replace(/&/g, '&'); escapedStr = escapedStr.replace(/</g, '<'); escapedStr = escapedStr.replace(/>/g, '>'); escapedStr = escapedStr.replace(/"/g, '"'); escapedStr = escapedStr.replace(/'/g, "'"); return escapedStr; | |
htmlEscape()String.prototype.htmlEscape = function() { return this.replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/'/g, '''); console.log('<script>'.htmlEscape()); | |
htmlEscape()"use strict"; String.prototype.htmlEscape = function() return this. replace(/&/g, '&'). replace(/</g, '<'). replace(/>/g, '>'). replace(/"/g, '"'). replace(/\n/g, '<br/>'); ... | |
htmlEscape()String.prototype.htmlEscape = function() { var obj = document.createElement('div'); if (typeof obj.textContent != 'undefined') { obj.textContent = this; } else { obj.innerText = this; return obj.innerHTML; }; ... | |
htmlEscape()String.prototype.htmlEscape = function () { return this.replace(/"/g, '"').replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&'); }; | |
normalizeHtml()String.prototype.normalizeHtml = function () { return this.replace(/(\n|\r|\t|\s\s+)/gm, "").trim(); }; |