Javascript String escapeHTML()

Description

Javascript String escapeHTML()


String.prototype.escapeHTML = function() {
  return this./*from  w  w w. j  a va2 s  .c  o  m*/
    replace(/&/g, "&").
    replace(/</g, "&lt;").
    replace(/>/g, "&gt;").
    replace(/\"/g, "&quot;");
};

console.log("<&>".escapeHTML()); // -> "&lt;&amp;&gt;"

Javascript String escapeHTML()

String.prototype.escapeHTML = function()
{
  var m = {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': '&quot;', "'": '&#39;', "/": '&#x2F;'};

  return String(this).replace(/[&<>"'\/]/g, function(s)
  {/*from www.  j  av a 2 s .c o m*/
    return m[s];
  });
}

Javascript String escapeHTML()

String.prototype.escapeHTML = function(){
 var str = this.replace(/</g, '&lt;');
 return str.replace(/>/g, '&gt;');
};

Javascript String escapeHtml()

String.prototype.escapeHtml = function() {
 return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/\"/g, "&quot;");
};

Javascript String escapeHtml()

var entityMap = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#39;',
    '/': '&#x2F;'
};
String.prototype.escapeHtml = function() {
    return this.replace(/[&<>"'\/]/g, function (s) {
        return entityMap[s];
    });/*from ww w.  j a  v a  2s.c o m*/
};

function getCookie(name) {
    var cookieStr = document.cookie;
    var cookieList = cookieStr.split('; ');
    for (var i = 0; i < cookieList.length; i++) {
        var cookie = cookieList[i].split('=');
        if (cookie[0] == name) {
            return decodeURI(cookie[1]);
        }
    }
    return '';
}

Javascript String escapeHTML()

String.prototype.escapeHTML = function () {
  return(this.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;'));                                                 
};

Javascript String escapeHTML()

var __entityMap = {
 "&": "&amp;",
 "<": "&lt;",
 ">": "&gt;",
 '"': '&quot;',
 "'": '&#39;',
 "/": '&#x2F;'
};

String.prototype.escapeHTML = function() {
 return String(this).replace(/[&<>"'\/]/g, function(s) {
  return __entityMap[s];
 });/*from w  w  w . ja va2 s . c om*/
}



PreviousNext

Related