drifterz28
8/14/2013 - 2:36 PM

Safe email JS built with vanilla.js examples in the comments. change the atkey and dotkey if you would like.

Safe email JS built with vanilla.js examples in the comments. change the atkey and dotkey if you would like.

(function() {
    var atkey = '|asdjklfahlsdjkfh|',
        dotkey = '|askjdfhuuejd|',
        elHref, elText,
        elementList = document.querySelectorAll('a.safe-email');
    for (var x = 0; x < elementList.length; x++) {
        var elm = elementList[x];
        elHref = elm.getAttribute('title').replace(atkey, '@').replace(dotkey, '.');
        elText = (elm.innerHTML.length > 0) ? elm.innerHTML : elHref;
        elm.setAttribute('href', 'mailto:' + elHref);
        elm.innerHTML = elText;
        elm.removeAttribute('title');
    }
})();

/**
 * Example email link
 * <a class="safe-email" href="#" title="info|asdjklfahlsdjkfh|example|askjdfhuuejd|com"></a>
 * with content in link that you would like to keep
 * <a class="safe-email" href="#" title="info|asdjklfahlsdjkfh|example|askjdfhuuejd|com">Email me</a>
 */