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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Hide Email Script Browser Compatability

Status
Not open for further replies.

csiwa28

Programmer
Apr 12, 2001
177
I found this script that will hide email addresses on a website. When viewed in Firefox, it displays "TEST". When viewed in IE6 or IE7, it displays "TEST", but once i hover or click on it, it changes to "mailto:test@test%2Ecom". Any ideas on how to make it not change in IE?

Code:
<Script>
function mailMe(sDom, sUser){
  return("mail"+"to:"+sUser+"@"+sDom.replace(/%23/g,"."));
}
</script>

<a href="/contact/" onmouseover="javascript:this.href=mailMe('test%2Ecom','test');" onfocus="javascript:this.href=mailMe('test%2Ecom','test');">TEST</a>
 
You'd need to set 'window.status'. However, I'd advise against using JS for this sort of obfuscation, as it hampers SEO and accessibility, and you can simply view source to harvest the email address.

Why not use a contact form instead?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Dan. Not really familiar with Javascript, so would you mind showing me where to place "window.status"?

We have a contact form, but our company prefers having email addresses on there as well. Would ASCII encoding work better? I know it's easy to decode, but it's better than no prevention at all right?

Chris
 
I would remove the current events on the anchor and switch to using an onclick instead:
Code:
...
<a href="/contact/" onclick="window.location=mailMe('test%2Ecom','test');return false;">TEST</a>
...
The code will show /contact/ when you hover over the anchor, and will open an email to the mailto URI when the mouse is clicked. Since the original anchor href is not modified, the original link will remain visible in the status bar.

On a side note, please change your script block from:
Code:
<Script>
To the (correct) lowercase version, with a type attribute:
Code:
<script type="text/javascript">

Let us know how that goes!

Regards,
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
 
Excellent, it worked perfectly! Thank you very much Jeff.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top