472,142 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

Email hiding JavaScript not working :(

I put this together from some other scripts I am using on a site. I'm
trying to make a better email hiding script. It isn't working. Also, it
causes Internet Explorer 6 SP2 to block the script as "active content". :(

The idea is that if the user doesn't have JavaScript enabled, they will see
an image of the email address (that can't be read by email harvesting
programs). If JavaScript is enabled, the image will be hidden and the
javascript will generate the email address in an "mailto:" link text.

<script language=javascript>
<!--
var name = "contact"
var domain = "mysite.com"
document.write("Email: " + name + "@" + domain) // this is going to be
changed to a href=mailto: link...

// hides email image below if JavaScript is enabled
var obj;
obj = document.getElementById("email");
obj.style.display = "none";
//-->
</script>

<div id="email" style="display: inline;">
<img src="images/email.gif" alt="Email address" />
</div>
Aug 16 '05 #1
4 5034
web_design wrote:
I put this together from some other scripts I am using on a site. I'm
trying to make a better email hiding script. It isn't working. Also, it
causes Internet Explorer 6 SP2 to block the script as "active content". :(
There is little point in 'hiding' email addresses in web pages. Do a
search on "hide email address" and you will find many threads discussing
it. Here's one that's only a couple of weeks old:

<URL:http://groups-beta.google.com/group/news.admin.net-abuse.email/browse_frm/thread/52b865188d082c35/22ae192f3ff1a9ef?q=hide+email+address&rnum=4&hl=en #22ae192f3ff1a9ef>

It is generally accepted that a form is better than depending on the
user having an email client configured to respond to 'mailto:'.

The idea is that if the user doesn't have JavaScript enabled, they will see
an image of the email address (that can't be read by email harvesting
programs). If JavaScript is enabled, the image will be hidden and the
javascript will generate the email address in an "mailto:" link text.

<script language=javascript>
Language is depreciated, type is required:

<script type="text/javascript">
<!--
HTML comments inside script tags are completely unnecessary and possibly
harmful. Don't use them.
var name = "contact"
var domain = "mysite.com"
document.write("Email: " + name + "@" + domain) // this is going to be
changed to a href=mailto: link...
Sufficient obfuscation may be:

document.write("Email: " + name + "@" + domain);

// hides email image below if JavaScript is enabled
var obj;
obj = document.getElementById("email");
obj.style.display = "none";
Or:

if ( document.getElementById ) {
var obj = document.getElementById("email");
}
if ( obj && obj.style ) {
obj.style.display = "none";
}

But it will still fail because the element with id 'email' doesn't exist
yet. Put the script below the element and you'll have a better chance
of success. Also, the image should only be hidden if the entire script
works (see below).
//-->
</script>

<div id="email" style="display: inline;">
<img src="images/email.gif" alt="Email address" />
Is this really XHTML? If not, use the HTML markup declaration close
delimiter (">") without a slash.
</div>

<script type="text/javascript">

if ( document.getElementById ) {
var obj = document.getElementById("email");
}
if ( obj && obj.style ) {
obj.style.display = "none";

// Replace with chosen obfuscation or whatever...
var name = "contact"
var domain = "mysite.com"
document.write("Email: " + name + "@" + domain)

}

</script>


--
Rob
Aug 16 '05 #2
JRS: In article <in**************@news.optus.net.au>, dated Tue, 16 Aug
2005 03:49:34, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.auau> posted :

There is little point in 'hiding' email addresses in web pages. Do a
search on "hide email address" and you will find many threads discussing
it. Here's one that's only a couple of weeks old:

<URL:http://groups-beta.google.com/group/...l/browse_frm/t
hread/52b865188d082c35/22ae192f3ff1a9ef?q=hide+email+address&rnum=4&hl=en #22ae19
2f3ff1a9ef>

It is generally accepted that a form is better than depending on the
user having an email client configured to respond to 'mailto:'.


It is not universally accepted (even disregarding those who provide
<TEXTAREA ROWS="3" WRAP="VIRTUAL" COLS="11"></TEXTAREA> to write in)
that only forms should be used, though.

Those who read Web pages off-line may find forms less convenient.

Those who like to keep records of E-mail will like to keep the
initiating message in the same form.

ISTM that the best approach (where forms can be used; I don't want to
provide such on my site) is to give the user a choice - provide a form
and also an E-mail address (not necessarily with mailto: or written /en
clair/) and, for businesses, an address for traditional mail too.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 16 '05 #3
"RobG" <rg***@iinet.net.auau> wrote in message
news:in**************@news.optus.net.au...
web_design wrote:
I put this together from some other scripts I am using on a site. I'm
trying to make a better email hiding script. It isn't working. Also, it
causes Internet Explorer 6 SP2 to block the script as "active content".
:(


There is little point in 'hiding' email addresses in web pages. Do a
search on "hide email address" and you will find many threads discussing
it. Here's one that's only a couple of weeks old:

<URL:http://groups-beta.google.com/group/news.admin.net-abuse.email/browse_frm/thread/52b865188d082c35/22ae192f3ff1a9ef?q=hide+email+address&rnum=4&hl=en #22ae192f3ff1a9ef>

It is generally accepted that a form is better than depending on the user
having an email client configured to respond to 'mailto:'.


Thanks for your JavaScript advice--I will put it to use.

I want to put the email address on the web site because I prefer it when I
can go to a web site and get an email address. Especially for
business-to-business correspondance. I also have a form on the site, but I
want to keep everyone happy. Also in this case it is for sending
attachments and I'd rather do it this way than write an upload form in PHP.
Aug 16 '05 #4

"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote in message
news:I8**************@merlyn.demon.co.uk...
JRS: In article <in**************@news.optus.net.au>, dated Tue, 16 Aug
2005 03:49:34, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.auau> posted :

There is little point in 'hiding' email addresses in web pages. Do a
search on "hide email address" and you will find many threads discussing
it. Here's one that's only a couple of weeks old:

<URL:http://groups-beta.google.com/group/...l/browse_frm/t
hread/52b865188d082c35/22ae192f3ff1a9ef?q=hide+email+address&rnum=4&hl=en #22ae19
2f3ff1a9ef>

It is generally accepted that a form is better than depending on the
user having an email client configured to respond to 'mailto:'.


It is not universally accepted (even disregarding those who provide
<TEXTAREA ROWS="3" WRAP="VIRTUAL" COLS="11"></TEXTAREA> to write in)
that only forms should be used, though.

Those who read Web pages off-line may find forms less convenient.

Those who like to keep records of E-mail will like to keep the
initiating message in the same form.

ISTM that the best approach (where forms can be used; I don't want to
provide such on my site) is to give the user a choice - provide a form
and also an E-mail address (not necessarily with mailto: or written /en
clair/) and, for businesses, an address for traditional mail too.


mailto links can be annoying (for example, when at an Internet cafe and it
suddenly opens up an unconfigured Outlook Express)... but it's very
convienient on my own computer. Also, if you use Firefox you can
right-click on a mailto link and the first item on the context menu is "copy
email address". Very handy.
Aug 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Nel | last post: by
2 posts views Thread by Jim | last post: by
8 posts views Thread by TravelMan | last post: by
8 posts views Thread by pcchong | last post: by
2 posts views Thread by c.anandkumar | last post: by
17 posts views Thread by HornyLaBelle | last post: by
2 posts views Thread by Gernot Frisch | last post: by
24 posts views Thread by Kourosh | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.