Simpliest way to obfuscate e-mail address using jQuery

Here is a simpliest jQuery code to protect e-mail addresses on your website from spam bots. Just put this in a script tag into the head section:

$(window).load(function() {			
	// anti spam
	var r='random-string';

	$('.'+r).each(function() {
	var $this = $(this),
		value = new String($this.text());

		value = value.replace('['+r+']', '@');

		$this.replaceWith($('').text(value).attr('href', 'mailto:'+value));

Now replace random-string with any really aleatory set of characters eg. dhhIDu338

And here is the HTML part. Publish every e-mail address on your page using this code:

Contact: johndoe[random-string]


0 responses to “Simpliest way to obfuscate e-mail address using jQuery”

  1. David Avatar

    Thanks for this. It has proven to be a dependable friend.

    I follow your “Contact” line with the following, for those super-cautious visitors having script disabled:

    To send an email, use the above address with “[stuff]” replaced by the “at” symbol.

    To obfuscate these instructions, some or all of the content can be entered in reverse order, which then depends only upon CSS to display correctly:

    .fcukoff {
    unicode-bidi: bidi-override; direction: rtl;

    In other words,
    in HTML appears in the browser as: