Ralpharama Archive. The archive is almost 20 years old, this website is no longer maintained.

Home | New Writing | Old Writing | Cooking | Technical | Wine Making | Cocktails
   
 
Misc

Javascript Smart-tag Stripper

Hits 4891 | Created 2007-07-24 | Modified 2007-07-24

This can be used to strip evil smart tags from text that is often submitted via copy and paste from, say, Microsoft Word. In this case you submit the id name of an element that contains the text (e.g. a textarea)

function fixit(elemname) {
	elem = document.getElementById(elemname);
	txt = elem.value;
	txt = txt.replace(String.fromCharCode(145), "'");
	txt = txt.replace(String.fromCharCode(146), "'");
	txt = txt.replace(String.fromCharCode(147), String.fromCharCode(34));
	txt = txt.replace(String.fromCharCode(148), String.fromCharCode(34));
	txt = txt.replace(String.fromCharCode(150), "-");
	txt = txt.replace(String.fromCharCode(151), "--");
	txt = txt.replace(String.fromCharCode(180), "'");
	txt = txt.replace(String.fromCharCode(184), ",");
	txt = txt.replace(String.fromCharCode(149), "");
	txt = txt.replace(String.fromCharCode(133), "...");
	txt = txt.replace(String.fromCharCode(132), String.fromCharCode(34));
	txt = txt.replace(String.fromCharCode(152), "~");
	txt = txt.replace(String.fromCharCode(126), "~");
	for (i=129;i<256;i++) {
		c = "&#" + i + ";"
		txt = txt.replace(String.fromCharCode(i), c);
	}
	elem.value=txt;
}




Make a Comment

Name
Comment


Antispam Code (always a number)

Enter Code Above
Submit

Note: All HTML will be removed except for bold and italics. Links will not display. Line breaks are added automatically. Use <pre>...</pre> for code.

Tags

This item has the following tags:
tech javascript tags

Useful? Donate for hosting costs

All content copyright (c) Ralpharama