Return to Snippet

Revision: 17479
at September 6, 2009 21:25 by enchance


Initial Code
String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};


//Usage 1:
var tmp = '<html><head></head>';
var safe= tmp.htmlEntities(); // Returns 
"&lt;html&gt;&lt;head&gt;&lt;/head&gt;"

Initial URL

                                

Initial Description

                                

Initial Title
Convert to HTML entities

Initial Tags
html, convert

Initial Language
JavaScript