Forum Moderators: open

Message Too Old, No Replies

Link to External Javascript

How To?

         

dimo414

3:33 am on Oct 25, 2005 (gmt 0)

10+ Year Member



I found a javascript code online that hides e-mail addresses from spambots. It's only problem is the code is very long and I don't like to insert it at the top of every page. The script is run by clicking an anchor, so where I want to insert the encrypted link, I insert this:

<a href='javascript:beat'>Email Me</a>

Like I said, the code itself is very long, so I want to make a seperate file with just the code (say, 'mailcode.htm'), and link to that. So my question is, what do I insert into the "href='javascript:beat'" in order to referance the script externaly?

a1call

3:40 am on Oct 25, 2005 (gmt 0)

10+ Year Member



Hi,
Use:

<SCRIPT LANGUAGE="JavaScript" SRC="file.js"></SCRIPT>

for external file.js. Don't put the js tag in the external file, just the js code.

Had to edit: I misunderstood the question. Sorry, I only know the above code is used to access external js. Not sure it will work in this case.
That seems to be the format:

<a href="#" onclick="javascript:functin()">

So write the function in a file with extension .js
and put the reference to it in the head of the html document. Not sure if other extensions will work but .js will. Hope this helps.

Robin_reala

6:48 am on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although a1call's got the right idea his code examples aren't quite correct. Valid vesions would be:

<SCRIPT type="text/javascript" SRC="file.js"></SCRIPT>

@language is deprecated in favour of @type.

<a href="#" onclick="functin()">

You don't need the javascript: pseudoprotocol if you're calling a function from an event handler.

kaled

9:20 am on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better to use an image rather than javascript. If javascript is disabled users can still see the address and type it in.

Kaled.

Tidal2

1:39 pm on Oct 25, 2005 (gmt 0)

10+ Year Member



"Better to use an image rather than javascript. If javascript is disabled users can still see the address and type it in."

What if they were using a speech reader?

You could cover Javascript being turned off with an extra line:

<noscript><img src="email.jpg"></noscript>

dimo414

3:00 am on Oct 26, 2005 (gmt 0)

10+ Year Member



Thanks for the code examples!

The problem with images is severalfold. One, most spambots look for 'mailto:' in site sources, so an image won't help much, unless of course you don't link to it. Beyond that, simply the issue of using an image in a way that it can flow with the text.

The code I'm refering to hides the e-mail address, but when the link is clicked, it acts as a mailto: command.

Anyways, thanks!

BlobFisk

8:49 am on Oct 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Best to avoid mailto: and use a form-to-mail prcessor instead. Not only does it hide your email address (if that's what you want), but it also allows people who don't have a default mail application (web mail users and people from web cafes) to contact you.

Dijkgraaf

8:58 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But using a formail processer might also open you up to those who search for vunerable ones that they can use for spamming.

I use an external JavaScript function to write the mailto: links to the page with a backup of an image for those with no JavaScript, and so far that address has not been spammed.

g1smd

12:52 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Javascript-written mailto: links are a good idea. A friend has reduced incoming spam from 1000 per day to under 80 per day within a year by doing just that.

For browsers without javascript, use an unlinked image that contains a visual rendition of the email address. Users will just have to re-type that to send mail.