Possible Duplicate:
How to escape HTML
How can a string be converted to HTML in JavaScript?
e.g.
var unsafestring = "<oohlook&atme>"; var safestring = magic(unsafestring);
where safestring
now equals "<ohhlook&atme>"
I am looking for magic(...)
. I am not using JQuery for magic
.
HtmlDecode(String, TextWriter) Converts a string that has been HTML-encoded into a decoded string, and sends the decoded string to a TextWriter output stream.
In order to encode/decode a string in JavaScript, We are using built-in functions provided by JavaScript. btoa(): This method encodes a string in base-64 and uses the “A-Z”, “a-z”, “0-9”, “+”, “/” and “=” characters to encode the provided string.
function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); }
So then with var unsafestring = "<oohlook&atme>";
you would use htmlEntities(unsafestring);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With