Posted By

Nick___ on 01/22/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Nick___


Escape HTML (one-liner)


 / Published in: JavaScript
 

  1. String.prototype.htmlEscape = function()
  2. {return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/\>/g,'&gt;')}
  3.  
  4.  
  5. // test it out...
  6. alert( '<a href="/?foo=1&bar=2"> blah </a>'.htmlEscape() );

Report this snippet  

You need to login to post a comment.