Every line of 'javascript html encode string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
67 function _htmlEncode(str) { 68 if (Array.isArray(str) || typeof str === 'object') { 69 return encodeURIComponent(JSON.stringify(str)); 70 } 71 else { 72 return encodeURIComponent(str + ''); 73 } 74 }
83 function htmlEncode(string) { 84 var HTML_CHARS = { 85 '&': '&', 86 '<': '<', 87 '>': '>', 88 '"': '"', 89 "'": ''', 90 '/': '/', 91 '`': '`' 92 }; 93 return (string + '').replace(/[&<>"'\/`]/g, function (match) { 94 return HTML_CHARS[match]; 95 }); 96 };
15 static htmlEncode(string) { 16 return $('<div>').text(string).html(); 17 }</div>
83 function htmlEncode(str) { 84 var div = document.createElement("div"); 85 div.appendChild(document.createTextNode(str)); 86 return div.innerHTML; 87 }
1 function htmlEncode(html) { 2 return document.createElement('a').appendChild(document.createTextNode(html)).parentNode.innerHTML; 3 }
106 function htmlencode(str) { 107 if (!str) { return ''; } 108 return str.replace(/&/g, '&').replace(//g, '>'); 109 }
584 function _htmlEncode(str) { 585 return str.replace(/[{}()\[\]<>!@#$%^&*\/\\'"+=,.?]/g, match => { 586 let charCode = match.charCodeAt(0); 587 return `#${charCode};`; 588 }); 589 }
11 function htmlEncode(html : string = '') : string { 12 return html.toString() 13 .replace(/&/g, '&') 14 .replace(//g, '>') 15 .replace(/"/g, '"') 16 .replace(/'/g, ''') 17 .replace(/\//g, '/'); 18 }
58 function htmlencode(html) { 59 return html 60 .replace(/&/g, '&') 61 .replace(//g, '>') 62 .replace(/"/g, '"') 63 .replace(/'/g, ''') 64 .replace(/\//g, '/'); 65 }
111 function html_encode(html){ 112 if(!html)return html; 113 var temp = document.createElement ("div"); 114 (temp.textContent != undefined ) ? (temp.textContent = html) : (temp.innerText = html); 115 var output = temp.innerHTML; 116 temp = null; 117 return output; 118 }