There is a wonderful script out there that populates email address, based on three elements passed to it: user, domain and suffix.
That script uses JavaScript to populate the mailto link, therefore making it inaccessible for spammers, which is something to take into consideration, especially if you’re a big corporate company. That is something I had to do for one of our sites.
Script itself is very easy:
<script language=”JavaScript”>
var user;
var domain;
var suffix;
function jemail(user, domain, suffix){
document.write(’<a href=”‘ + ‘mailto:’ + user + ‘@’ + domain + ‘.’ + suffix + ‘”>’ + user + ‘@’ + domain + ‘.’ + suffix + ‘</a>’);
}
</script>
To populate the mailto link, you use it like that:
<script language=”JavaScript”>jemail(”test”, “mailserver”, “com”);</script>
However, all of the emails are stored as actual email adresses in our DB, looking like test@mailserver.com.
I couldn’t find anywhere online a tool to get those three elements of email address to use in that function, so I had to write it myself. Decided I’d share it with someone who might be looking for the same solution I was looking for.
Here is the code (assuming emailAddress is your DB field for email):
ColdFusion
<cfset user = RemoveChars(emailAddress, Find(”@”, emailAddress), Len(emailAddress))>
<cfset domain = RemoveChars(emailAddress, 1, Find(”@”, emailAddress))>
<cfset domain = RemoveChars(domain, Find(”.”, domain), Len(domain))>
<cfset suffix = RemoveChars(emailAddress, 1, Find(”.”, emailAddress))>JavaScript
<script language=”JavaScript”>jemail(”#user#”, “#domain#”, “#suffix#”);</script>
). The reason it does that is because the swf is loaded externally and therefore onReleaseOutside listener simply don’t work, because there is kind of no outside because it is always inside (wait, dude, WHAT???). Now, I am sure it is fixable, but here is the reason why it is not fixed – I am lazy.