Javascript email address

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
heavener
Beginner
Beginner
Posts: 8
Joined: Mon Aug 23, 2004 6:52 pm
Location: Redmond, Washington USA
Contact:

Javascript email address

Post by heavener »

I use a snippet of javascript (see below) every time I want to display my email address on my web site.This seems to eliminate spammers spidering the address.

Unfortunately, the script doesn't fit into the Milonic menus, even with the added flexibility of version 5.

Is there any way I can add this kind of parsing to the Milonic script?

<script language="Javascript">
a_mail_name = "heavener"
a_mail_domain = "heavenr.com"
document.write("<a href='mailto:" + a_mail_name + "@" + a_mail_domain + "'>");
document.write("<span style='color:Maroon;text-decoration:none;'>");
document.write(a_mail_name + "@" + a_mail_domain);
document.write("</span></a>");
</script>

The web site/menu is located at http://www.heavenr.com
Sincerely,
Michael Heavener, ABC
heavener@heavenr.com
425 885-0961
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Hi,

What you need to do is put your code inside a function with a return value of your email address.

Here's the function:

Code: Select all

function myEmail()
{
	a_mail_name = "heavener" 
	a_mail_domain = "heavenr.com" 
	retEmail="<a href='mailto:" + a_mail_name + "@" + a_mail_domain + "'>"
	retEmail+="<span style='color:Maroon;text-decoration:none;'>"
	retEmail+=a_mail_name + "@" + a_mail_domain
	retEmail+="</span></a>"
	return retEmail
}
This can go inside the menu_data.js file but the function needs to be included before you call it. So the best place to put this function is at the top of your data file.

To call this function, try this:

Code: Select all

aI("text="+myEmail()+";type=html;");
Hope this helps
Andy
heavener
Beginner
Beginner
Posts: 8
Joined: Mon Aug 23, 2004 6:52 pm
Location: Redmond, Washington USA
Contact:

Post by heavener »

Your code snippet works great ... except the mouseover text color does not change. The URL is http://www.heavenr.com
Sincerely,
Michael Heavener, ABC
heavener@heavenr.com
425 885-0961
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

If you remove the HTML for the span and let the menu control the colors, it will work as expected. You also need to remove the type=html; part

Here's another snippet.

Code: Select all

function myEmail()
{
	a_mail_name = "heavener" 
	a_mail_domain = "heavenr.com" 
	return a_mail_name+"@"+a_mail_domain
}
then your aI() string should look like this:

Code: Select all

aI("text="+myEmail()+";url=mailto:"+myEmail());
If you have access to PHP you could also use the encoding function:

Code: Select all

function emailEnc($email)
{
	$retEmail="";
	for($a=0;$a<strlen($email);$a++)$retEmail.="&#".ord($email[$a]).";";
	return $retEmail;
}
Cheers
Andy
Post Reply