[thelist] Using JavaScript for non-clickable email addresses

Jono ox4dboy at comcast.net
Mon Jan 31 09:42:36 CST 2005

I started this thread a while back, and have settled on a temporary 
solution, using a combination of things I found through [theList].  I 
think it is a reasonable good approach to the problem, as far as 
non-server-side approaches go.  It validates and has been tested on IE 
6, FF, and Netscape 7 for PC, and FF, Safari, IE 5.2.3 for Mac OS 
10.3.7.   I also tested this with JAvascript disable and enabled in FF 
on both platforms.  I will outline what I have done for anyone who 
might need something like this in the future:

: :  |    T H E     H T M L    |  : :

<script type="text/javascript" language="javascript" 
<script type="text/javascript" language="javascript" 

  <!-- F O R    P L A I N - T E X T    E M A I L    A D D R E S S E S    
<!-- the code below calls to email-fix.js -->
<p><a name="anchor1" onmouseup="hello(this)"><span 

<!-- F O R   C L I C K A B L E    E M A I L    A D D R E S S E S    -->
<!-- the code below calls to email-fix.js and email.js -->
<!-- <noscript> calls email-fix.js, and <script> calls email.js -->
subject here&body=email body text here","Contact Us NOW")</script>
Contact Us NOW: <a name="anchor1" onmouseup="hello(this)"><span 

: :  |    T H E     J A V A S C R I P T    |  : :

// this is email-fix.js
// courtesy of Robert Vreeland
<script type="text/javascript">
function hello(){
  linkArray = "";
  if(arguments[0].nodeName == ("A" || "a")){
   linkArray = "mailto:";
   linkArray = linkArray + arguments[0].firstChild.innerHTML;
   linkArray = linkArray + "@";
   linkArray = linkArray +
   arguments[0].href = linkArray;


// this is email.js
// courtesy of http://www.bronze-age.com/nospam/
// Email.js version 5
var tld_ = new Array()
tld_[0] = "com";
tld_[1] = "org";
tld_[2] = "net";
tld_[3] = "ws";
tld_[4] = "info";
tld_[10] = "co.uk";
tld_[11] = "org.uk";
tld_[12] = "gov.uk";
tld_[13] = "ac.uk";
var topDom_ = 13;
var m_ = "mailto:";
var a_ = "@";
var d_ = ".";

function mail(name, dom, tl, params)
	var s = e(name,dom,tl);
	document.write('<a href="'+m_+s+params+'">'+s+'</a>');
function mail2(name, dom, tl, params, display)
function e(name, dom, tl)
	var s = name+a_;
	if (tl!=-2)
		s+= dom;
		if (tl>=0)
			s+= d_+tld_[tl];
		s+= swapper(dom);
	return s;
function swapper(d)
	var s = "";
	for (var i=0; i<d.length; i+=2)
		if (i+1==d.length)
			s+= d.charAt(i)
			s+= d.charAt(i+1)+d.charAt(i);
	return s.replace(/\?/g,'.');

More information about the thelist mailing list