Subscribe to RSS

Some rights reserved

Except where otherwise noted, content on this site is licensed under a Creative Commons License


programming‎ > ‎javascript‎ > ‎

Making email addresses more spambot safer

Plain Old Javascript

function expandMail() {
  var a1 = "mail"
  var a2 = "to"
  var a3 = "user@my"
  var a4 = "company.com"
  document.getElementById("email").href = a1 + a2 + ":" + a3 + a4
}

<a id="email" href="" onclick="expandEmail()">Contact Me</a>

EVENT BINDING ON MARKUP

  

Unobtrusive JavaScript using JQuery

$(document).ready(function() {
   $('#email').bind('click', function(event) {
     var c = ["foo", "@", "bar.com"]
     $('#email').attr({'href': "mailto:" + c.join("")});
   });
});

<a id="info" href="">Contact Me</a>

NO EVENT BINDING ON MARKUP!