Reputation: 36654
On a website, I retrieve a string the user entered.
DataItem.getProperty('-----some name ----')
The problem is that some users put a <script></script>
in there.
How can I escape/html-encode this string nicely ?
Upvotes: 1
Views: 269
Reputation: 175766
How about;
function HTMLEncode(buff) {
var e = document.createElement("div");
e.appendChild(document.createTextNode(buff));
return e.innerHTML;
}
In: AAA <script>BBB</script> CCC <DDD>
Out: AAA <script>BBB</script> CCC <DDD>
Upvotes: 1