Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript, Usemap and Mailto

Status
Not open for further replies.

jswannabe

Programmer
Aug 10, 2007
8
US
I'm a real rube at JavaScript, so I apologize in advance if this question is overly stupid...

I'm workng on a client's new website and am trying to avoid all of the spambots out there by excuting a "mailto" from JavaScript. This wouldn't be much of an issue except that I'm working with an imagemap and I can't figure out how to actually get the "mailto" to fire apropriately.

Here's my html code:

Code:
<td width="365" valign="top"><img src="images/header_right.gif" width="365" height="188" usemap="#emailtest" border="0" />



<map name="emailtest" id="emailtest">
  <area shape="rect" coords="180,91,354,110"  alt="Email Us!" href="javascript:emailMap();"  />
</map>



And here's the javascript (substitute some real domain name for "clientdomainname" below):

			<script type="text/JavaScript">
			
			function emailMap(){
			var first = 'ma';
			var second = 'il';
			var third = 'to:';
			var address = 'jim';
			var domain = 'clientdomainname';
			var ext = 'com'; 
			outstring = "";
			outstring = outstring+first+second+third;
			outstring = outstring+address;
			outstring = outstring + '@';
			outstring = outstring + domain;
			outstring = outstring+'.';
			outstring = outstring+ext; 

			window.open(outstring);

			}
			
			</script>

On first pass, this Seems to be working ok in IE, but Mozilla & Netscape open a blank window behind the email client window.

Any help would be appreciated.

Thanks!
 
Try a minor addition to the href:
Code:
href="javascript:emailMap();[!]return false;[/!]"
See how that works.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks for the feedback, Jeff. Unfortunately, I get an error by adding the return false; as part of the href.

IE gives its wonderful "errors on page" in the status bar. Upon further investigation in Mozilla, the Error console says:

return not in function
href="javascript:emailMap();return%20false;" Line 1
href="javascript:emailMap();return false;"


I assume what we are trying to do here is return "false" to the browser application?

Any ideas to fix the error?

Thanks for your help!
 
You can ignore my suggestion regarding return false (as you can see it was next to useless for you). The solution is just as simple, however. Change the window.open line in your emailMap function to:
Code:
...
window.location = outstring;
...
Problem solved.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top