Click to See Complete Forum and Search --> : Javascript mailto Problem Newbie Question


wdolson
September 23rd, 2006, 07:41 AM
I've posted on the C++ forum before, but this is one of the few times I've had to venture into web programming and I've gotten a bit lost...

What I am attempting to do is make e-mail addresses on a site protected from spammers with a javascript. Searching the web, it looks like there are many variations on the technique I'm using. The twist is that our web developer wants to tie the e-mail link to a hotspot on a graphic.

Here is the script:

<script language="JavaScript" type="text/javascript">
function safemail(emailN, emailD, emailT) {
emailN=(emailN + '@' + emailD)
if(!emailT)
{ emailT = emailN}
document.write("<a href=\"mailto:" + emailN + "\">" + emailT + '')
}
</script>
<noscript>
You must have javascript enabled for this to work.
</noscript>

The bit that calls the script is:

<area shape="circle" coords="93,58,47" href="javascript:safemail('sales', 'sol-software.com')">

What this does is go to a new page with the e-mail link as the only item on the page. If you click on the link, it will bring up the e-mail compose window. How can I get this to open the e-mail compose window without going to the extra page?

Thanks in advance,
Bill

PeejAvery
September 23rd, 2006, 12:31 PM
So, you are trying to create a mailto link without putting the e-mail address there so that harvesters can't get an e-mail to spam.

Very simple code for you. Try the following.

<script language="JavaScript" type="text/javascript">
function ihatespam(address, domain){
var email = address + "@" + domain;
location.replace("mailto:" + email);
}
</script>
<noscript>
You must have javascript enabled for this to work.
</noscript>

<area shape="circle" coords="93,58,47" href="#" onclick="ihatespam('sales', 'sol-software.com')">

wdolson
September 23rd, 2006, 08:52 PM
I knew the answer was ultimately easy, just couldn't figure out the right combination.

Thanks a lot, :)
Bill

PeejAvery
September 24th, 2006, 08:22 PM
You're welcome.