Javascript String unescapeHtml()
String.prototype.unescapeHtml = function () { var temp = document.createElement("div"); temp.innerHTML = this;/*from w w w. j a va 2 s. co m*/ var result = temp.childNodes.length === 0 ? "" : temp.childNodes[0].nodeValue; if(temp.firstChild) temp.removeChild(temp.firstChild); return result; };
String.prototype.unescapeHtml = function () { var temp = document.createElement("div"); temp.innerHTML = this;/*w w w . j ava 2s . c om*/ var result = ""; for (var i = 0; i < temp.childNodes.length; i++) { result = result + temp.childNodes[i].nodeValue; } temp.removeChild(temp.firstChild) return result; }
String.prototype.unescapeHtml = function () { var temp = document.createElement("div"); temp.innerHTML = this;//from ww w . java 2s . c om var result = temp.childNodes[0].nodeValue; temp.removeChild(temp.firstChild); return result; }
/**/*from w ww . j a v a2 s . co m*/ * Extended Objects * * Adds additional methods to javascript built-in types */ // Function for unescaping HTML encoded characters String.prototype.unescapeHtml = function () { // Create a fake element and assign our string to its contents var temp = document.createElement("div"); temp.innerHTML = this; // Get the contents (now natively escaped), remove the child node and retuin var result = temp.childNodes.length === 0 ? "" : temp.childNodes[0].nodeValue; if(temp.firstChild) temp.removeChild(temp.firstChild); return result; };
String.prototype.unescapeHTML = function() { return String(this).replace("&", "&").replace("<", "<").replace(">", ">").replace('"', '"').replace(''', "'").replace('/', "/"); }