Connecting Tech Pros Worldwide Help | Site Map

Email hiding JavaScript not working :(

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 16th, 2005, 03:35 AM
web_design
Guest
 
Posts: n/a
Default 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>



  #2  
Old August 16th, 2005, 03:55 AM
RobG
Guest
 
Posts: n/a
Default Re: Email hiding JavaScript not working :(

web_design wrote:[color=blue]
> 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". :([/color]

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:'.
[color=blue]
>
> 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>[/color]

Language is depreciated, type is required:

<script type="text/javascript">
[color=blue]
> <!--[/color]

HTML comments inside script tags are completely unnecessary and possibly
harmful. Don't use them.
[color=blue]
> var name = "contact"
> var domain = "mysite.com"
> document.write("Email: " + name + "@" + domain) // this is going to be
> changed to a href=mailto: link...[/color]

Sufficient obfuscation may be:

document.write("Email: " + name + "@" + domain);
[color=blue]
>
> // hides email image below if JavaScript is enabled
> var obj;
> obj = document.getElementById("email");
> obj.style.display = "none";[/color]

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).
[color=blue]
> //-->
> </script>
>
> <div id="email" style="display: inline;">
> <img src="images/email.gif" alt="Email address" />[/color]

Is this really XHTML? If not, use the HTML markup declaration close
delimiter (">") without a slash.
[color=blue]
> </div>[/color]


<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
  #3  
Old August 16th, 2005, 10:55 PM
Dr John Stockton
Guest
 
Posts: n/a
Default Re: Email hiding JavaScript not working :(

JRS: In article <indMe.40$uQ6.677@news.optus.net.au>, dated Tue, 16 Aug
2005 03:49:34, seen in news:comp.lang.javascript, RobG
<rgqld@iinet.net.auau> posted :[color=blue]
>
>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:'.[/color]

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.
  #4  
Old August 16th, 2005, 11:05 PM
web_design
Guest
 
Posts: n/a
Default Re: Email hiding JavaScript not working :(


"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
news:I8E+TvG6TkADFwUy@merlyn.demon.co.uk...[color=blue]
> JRS: In article <indMe.40$uQ6.677@news.optus.net.au>, dated Tue, 16 Aug
> 2005 03:49:34, seen in news:comp.lang.javascript, RobG
> <rgqld@iinet.net.auau> posted :[color=green]
>>
>>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:'.[/color]
>
> 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.[/color]

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.


  #5  
Old August 16th, 2005, 11:05 PM
web_design
Guest
 
Posts: n/a
Default Re: Email hiding JavaScript not working :(

"RobG" <rgqld@iinet.net.auau> wrote in message
news:indMe.40$uQ6.677@news.optus.net.au...[color=blue]
> web_design wrote:[color=green]
>> 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".
>> :([/color]
>
> 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:'.[/color]

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.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.