Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Hide Email Address From Spammers With Javascript

DZone's Guide to

Hide Email Address From Spammers With Javascript

·
Free Resource

function mangle() {
	if (!document.getElementsByTagName && !document.createElement &&
		!document.createTextNode) return;
	var nodes = document.getElementsByTagName("span");
	for(var i=nodes.length-1;i>=0;i--) {
		if (nodes[i].className=="change") {
			var at = / at /;
			var dot = / dot /g;
			var node = document.createElement("a");
			var address = nodes[i].firstChild.nodeValue;

			address = address.replace(at, "@");
			address = address.replace(dot, ".");

			address = address.replace(at, "@");
			address = address.replace(dot, ".");
			node.setAttribute("href", "mailto:"+address);
			node.appendChild(document.createTextNode(address));
			
			var prnt = nodes[i].parentNode;
			for(var j=0;j
  
   

You can use this script, if you'd like to post your email address to your homepage, but don't want to see it picked up by spammers.

Just run it in your onload event handler and mark emails in your HTML as:

      
   markos at gaivo dot net

This way they are still recognizable by those who don't use javascript.

If you need help or want to discuss this code, please do it on my 
   blog.
  
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}