Every line of 'html encode javascript' 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 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
15 static htmlEncode(string) { 16 return $('<div/>').text(string).html(); 17 }
1 function htmlEncode(html) { 2 return document.createElement('a').appendChild(document.createTextNode(html)).parentNode.innerHTML; 3 }
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 }
58 function htmlencode(html) { 59 return html 60 .replace(/&/g, '&') 61 .replace(/</g, '<') 62 .replace(/>/g, '>') 63 .replace(/"/g, '"') 64 .replace(/'/g, ''') 65 .replace(/\//g, '/'); 66 }
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 };
83 function htmlEncode(str) { 84 var div = document.createElement("div"); 85 div.appendChild(document.createTextNode(str)); 86 return div.innerHTML; 87 }
131 function htmlEncode(value) { 132 // Code to prevent xss attack 133 var temp_div = document.createElement("div"); 134 temp_div.textContent = value; 135 return temp_div.innerHTML; 136 }
96 function htmlencode(html) { 97 return html 98 .replace(/&/g, '&') 99 .replace(/</g, '<') 100 .replace(/>/g, '>') 101 .replace(/"/g, '"') 102 .replace(/'/g, ''') 103 .replace(/\//g, '/'); 104 }
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 .replace(/\//g, '/'); 19 }