oppure copia e incolla questo
codice:
function escapeChar(str){
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/"/g, "&#34;");
  str = str.replace(/'/g, "&#39;");
  str = str.replace(/\//g, "&#47;");
  str = str.replace(/\\/g, "&#92;");	
  return str;
}