Forum Moderators: open

Message Too Old, No Replies

Javascript mail hiding help

Mail script does not work in all browsers

         

Disabled Master

5:08 pm on May 10, 2004 (gmt 0)

10+ Year Member



I built a little javascript function to hide my email address from auto detection and (hopefully) spammers. It works great in IE and Opera but fails in Netscape 7.1 and Mozilla Firebird. I'm wondering if anyone can tell me why. The script and its usage is as follows:

<script language=javascript>
<!--
function mref() {
temp = "fakeaddress@someurl.com?" +
"subject=My%20Subject";
temp = "mailto:" + temp;
mymail.href=temp;
return true;
}
// -->
</script>

<P><a name="mymail" href="#" onclick="mref()"><img
src="mailimage.gif" alt="e-MAIL" align="right"></a>

Disabled Master

6:32 pm on May 10, 2004 (gmt 0)

10+ Year Member



Additional information. I placed alert statements in the function body and determined that the function mref is called in all the tested browserrs and that the variable temp is set correctly. The problem seems to be that Netscape and Mozilla ignore the statement

mymail.href=temp;

while IE and Opera process this statement. Strange.

DrDoc

6:42 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should fix it:

<script language=javascript>
function mref(which) {
temp = "fakeaddress@someurl.com?" + "subject=My%20Subject";
temp = "mailto:" + temp;
which.href=temp;
//return true;
}
</script>

<a href="#" onmousedown="mref(this)"><img src="mailimage.gif" alt="e-MAIL" align="right"></a>

I use onmousedown instead of onclick to make sure that the href is set before the link is actually clicked. Also, I pass "this" as an identifier to the function.

Disabled Master

6:57 pm on May 10, 2004 (gmt 0)

10+ Year Member



Thanks DrDoc - that did the trick. Clearly simple functions can teach us alot!