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

re: using javascript instead of "mailto" for email to avoid spam......

Status
Not open for further replies.

2socks

Programmer
Mar 13, 2002
2
IE
Hi,

On one of my webapges where emails are links,I use some javascript instead of the usual i.e <a href=&quot;mailto:joe@bloggs.com&quot;> , so to avoid spam email etc.

heres the alternative javascript for joe@bloggs.com

<a href='javascript:window.location=&quot;mai&quot;+&quot;lto:&quot;+&quot;joe&quot;+&quot;@&quot;+&quot;bloggs&quot;+&quot;.&quot;+&quot;com&quot;;'
ONMOUSEOVER='window.status=&quot;mai&quot;+&quot;lto:&quot;+&quot;+&quot;joe&quot;+&quot;@&quot;+&quot;bloggs&quot;+&quot;.&quot;+&quot;com&quot;;'return false;'
ONMOUSEOUT='window.status=&quot;&quot;;return false;'>joe@bloggs.com</a>

on the webpage it looks like a normal email link, but you'll see the javascript on the status bar. My PROBLEM is, with Netscape 4.7, its fine, but IE 6+ it opens a blank page plus the email window. I don't want the blank page, I want it to stay on the relevant page. Can anyone suggest some more script to avoid this...i want it to be browser compatible...atleast with the popular ones NS and IE atleast. I have tried some scripts but its then either ok in NS and not in IE. I can't seem to win!
thanks,
2socks
 
Hi 2socks
You can use your IE specific code and your NetScape specific code at the same time. You just have to do some &quot;browser-sniffing&quot;. Use the appName property of the Navigator object (don't worry, the Navigator object is supported by IE, in spite of the name).

e.g. var thisBrowser = new Object();
thisBrowser.name = Navigator.appName

if (thisBrowser.name == &quot;IE&quot;){
// IE code here
}
else if (thisBrowser.name == &quot;Netscape&quot;){
// NN code here
}
 
try using something like this :

function email() // stops bots
{
document.write(&quot;<a href='&quot;
+ &quot;mailto:&quot;
+ &quot;gary&quot;
+ &quot;135&quot;
+ &quot;@&quot;
+ &quot;hotmail&quot;
+ &quot;.&quot;
+ &quot;com?subject=Freelancing request'&quot;
+&quot;>gary&quot;
+ &quot;135&quot;
+ &quot;@&quot;
+ &quot;hotmail&quot;
+ &quot;.&quot;
+ &quot;com&quot;
+ &quot;</a>&quot;);
}

The anywhere you want to write your email addy just use <script> email() </script>

Took it from my web site. Hope this helps. Gary Haran
 
Have you tried to simply put &quot;return false;&quot; at the end of your JavaScript code in the HREF attribute? Don't know if that will work, but you didn't mention it, so I did!
 
Question was sent to my email addy :

If you have a moment, can you explain how
the Javascript function &quot;stops bots&quot;?

Thanks.

BTW, did you know that you page ( does not work correctly
in Netscape 4.7? Specifically, your email address does not appear.)
=========================================================

I prefer answering question in this forum that way everyone can learn and have their input.

1. stops bots?

Bots is a term used for computer programs that follow all kinds of links on web pages. On the pages the robot goes it uses regular expressions to extract email addresses and adds these to a list of email addresses. These email addresses are then sold or used by spammers.

2. netscape 4.7

I realise that not everything works in Netscape 4.x on my site. As stated on my site all the work on there is experimental.

I don't have NS4 but maybe this can fix the problem :

function email() // stops bots
{
document.write(&quot;<&quot;
+ &quot;a href='&quot;
+ &quot;mailto:&quot;
+ &quot;gary&quot;
+ &quot;135&quot;
+ &quot;@&quot;
+ &quot;hotmail&quot;
+ &quot;.&quot;
+ &quot;com?subject=Freelancing request'&quot;
+&quot;>gary&quot;
+ &quot;135&quot;
+ &quot;@&quot;
+ &quot;hotmail&quot;
+ &quot;.&quot;
+ &quot;com&quot;
+ &quot;<&quot;
+ &quot;/a>&quot;);
}

Maybe that will work but that is just guesswork from me. Somebody with NS4 can help.

Do you absolutly need to support NS4? Gary Haran
 
I am the one who asked that last question.

In Netscape 4.x, one cannot write to the document after it has loaded. In IE, certain portions of the document can be re-written at any time. In your page, does your email() function get invoked in-line as the page is being drawn or sometime later, after that portion of the page has been drawn? Just a thought.
 
The JS functions are invoked as the page is being written, and we have used this sort of thing for quite a while to keep email address harvesting programs from getting our clients' email addresses from their sites
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top