HTMLEncode method for javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.HTMLEncode = function (str) { | |
var result = ""; | |
var str = (arguments.length === 1) ? str : this; | |
for (var i = 0; i < str.length; i++) { | |
var chrcode = str.charCodeAt(i); | |
result += (chrcode > 128) ? "&#" + chrcode + ";" : str.substr(i, 1) | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These 9 lines of javascript code will extend the String object with a new method:
Used as a method on a string