Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Added: Jan 28, 2018 3:03 AM
Modified: Jan 28, 2018 3:04 AM
Views: 27
  1. var entityMap = {
  2.   '&': '&',
  3.   '<': '&lt;',
  4.   '>': '&gt;',
  5.   '"': '&quot;',
  6.   "'": '&#39;',
  7.   '/': '&#x2F;',
  8.   '`': '&#x60;',
  9.   '=': '&#x3D;'
  10. };
  11.  
  12. function escapeHtml (string) {
  13.   return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  14.     return entityMap[s];
  15.   });
  16. }