Javascript String htmlEscape()
String.prototype.htmlEscape = function() { return this.replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } console.log('<script>'.htmlEscape()); // <script>
String.prototype.htmlEscape = function() { return $('<div/>').text(this.toString()).html(); };
console.log('\nProblem 5. nbsp'); /*Write a function that replaces non breaking white-spaces in a text with  */ String.prototype.htmlEscape = function (){ var escapedStr = String(this).replace(/&/g, '&'); escapedStr = escapedStr.replace(/\s/g, ' '); return escapedStr; } var text = 'This is for testing'; console.log(text);//ww w .ja va 2 s.c o m text = text.htmlEscape(); //because string is immutable type console.log(text);
String.prototype.htmlescape = function () { return//from ww w. java2 s. co m this.replace(/&/g,'&'). replace(/>/g,'>'). replace(/</g,'<'). replace(/"/g,'"'); };
String.prototype.htmlEscape = function(){ var span = document.createElement('span'); var txt = document.createTextNode(''); span.appendChild(txt);/*w w w . j a v a2 s . c om*/ txt.data = this; return span.innerHTML; };
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; }
String.prototype.htmlescape = function () { return(/* w w w .j a va 2 s . c om*/ this.replace(/&/g,'&'). replace(/>/g,'>'). replace(/</g,'<'). replace(/"/g,'"') ); };