« Blog Home

§ Avoid email harvesting with javascript

I don't like to put real email addresses on web pages because "harvesters" look for them to add to their spam list.  However, harvesters probably don't run javascript before searching.

I put email addresses on pages like this:

<span class="emailaddress">"whatever at SlashbackAssociates.com"</span>

The javascript below changes it into a clickable email link in the user's browser.

The isArray() return... line probably should go all on one line, even though it seems to work fine as shown.  It's so long that it misleadingly wraps if I don't break it up.

 

function isArray(testObject) {
  return testObject
         && !(testObject.propertyIsEnumerable('length'))
         && typeof testObject === 'object'
         && typeof testObject.length === 'number';
}
function fixemails() {
  var emregex = /"(.+)\sat\s(.+)"/;
  var emailspans = document.getElementsByTagName("span");
  for(var i=0;i<emailspans.length;i++) {
    if(emailspans[i].className.indexOf("emailaddress") > -1) {
      var ea=emregex.exec(emailspans[i].innerHTML);
      if(isArray(ea)) {
        var newem=ea[1]+'@'+ea[2];
        emailspans[i].innerHTML=''+newem+'';
      }
    }
  }
}
function makeDoubleDelegate(function1, function2) {
  return function() {
    if (function1)
      function1();
    if (function2)
      function2();
  }
}
window.onload = makeDoubleDelegate(window.onload, fixemails);

 

 

last edited on August 19th, 2009 at 7:54 PM

Comments

No Comments Here. Add yours below!

Add your comment

Name:
Email: (Will not be displayed - Privacy policy)
Website:
Comments:
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)
 

« Blog Home

Comments

So all he had to do was learn some Norse magic.  Free Loki.  Find Liz.  Stop Ragnarok.  Help Sygin get her revenge on the lords of the Æsir.  Defeat the Krim, and get home.
Easy, really.
Jerry, Pyramid Power, Eric Flint & Dave Freer