Thursday 27 June 2002

Accessibility tip 08: Use real links

Mark Pilgrim directs our attention to “the scourge of web design.” It’s the javascript: link, “a pseudo-link that executes a piece of Javascript code when you click on it.” In weblogs, including mine until today, this is commonly used to display comments in a separate (smaller) window. Unfortunately, anyone whose browser doesn’t support JavaScript couldn’t make a comment on any of my posts.

The default templates in Movable Type and Radio UserLand don’t rely on JavaScript but my templates are derived from older versions that I’ve subsequently modified. Happily, implementing Mark’s fix took less than ten minutes.

Searching the template code for “javascript” also revealed that I was using JavaScript to create a spam-proof email link. Clicking on the word “Contact” in my navigation panel automatically opens the visitor’s email client (via a mail:to link) and creates a new message with my email address inserted in the To: field. Since spammers harvest email addresses from these mail:to links, I was using the following JavaScript to encode my email address, using character entities rather than actual text:

<script type="text/javascript">
<!--
document.write('<a href="mailto:&#106;&#111;&#110;&#97;&#116;&#104;&#111;&#110;
&#64;&#100;&#101;&#108;&#97;&#99;&#111;&#117;&#114;&#46;
&#110;&#101;&#116;" title="Send me an email message">Contact<\/a>');
// -->
</script>

But there doesn’t appear to be any reason to use a JavaScript document.write() command to accomplish this relatively simple task—or, if there is, I’m certain someone will quickly draw my attention to it. So I simply replaced the JavaScript with the encoded mail:to link:

<a href="&#109;&#097;&#105;&#108;&#116;&#111;&#058;&#106;&#111;
&#110;&#097;&#116;&#104;&#111;&#110;&#064;&#100;&#101;&#108;
&#097;&#099;&#111;&#117;&#114;&#046;&#110;&#101;&#116;"
title="Send me an email message">Contact</a>

This also fixed a problem with Mozilla 1.0, caused by the escaped forward slash (<\/a>) in the link.

And no, in case you’re worrying, you don’t have to encode your email address manually. The fantomas mailShield™ will do it for you.

Permalink | Technorati

Comments

Hello? Collusion again!!!

Can't you at least wait until mark puts his info up b efore you start linking to it and commenting on it?

Posted by tyler durden on 26 June 2002 (Comment Permalink)

Tyler, sshhh! Why can't you and I keep this as our little secret? If I hold off posting until I wake up tomorrow morning, that winds up being mid-afternoon on the West Coast and the end of the day on the East Coast. So I miss the chance of directing some traffic to Mark's site. And anyway, how come you're up so early?

Posted by Jonathon Delacour on 26 June 2002 (Comment Permalink)

Jonathon, I'm glad to see your comments links no longer use javascript. Now I don't have to mess with my security settings every time I read your weblog.

Posted by zem on 27 June 2002 (Comment Permalink)

Some thoughts on accessible spam-proofing over here.

Posted by Phil Ringnalda on 28 June 2002 (Comment Permalink)

Phil, that's certainly an ingenious approach. I worry though that people without JavaScript get the Spam Motel address. I'll have to get permission from Mark Pilgrim to use your fix.

And Zem, I'm glad that I've made it possible for you to comment.

Posted by Jonathon Delacour on 30 June 2002 (Comment Permalink)

Back when I used Spam Motel more often, I did worry that people who are used to addresses like bob@NOSPAMsmith.com would send mail to AKJSDL@motel.com. Possibly a contact form for the href would be better, though they have their own issues (I'm so used to commenting that being presented with a form asking for my name and email doesn't slow me down at all, but if you are picking out letters with a mouth stick, you would much rather be in your email client where your name and address are already taken care of for you).

Posted by Phil Ringnalda on 1 July 2002 (Comment Permalink)

chao ban

Posted by dao xuan hoa on 13 August 2002 (Comment Permalink)

ist angekommen

Posted by pedro on 27 August 2002 (Comment Permalink)

bye, bye

Posted by stefano on 29 August 2002 (Comment Permalink)

bye, bye

Posted by stefano on 29 August 2002 (Comment Permalink)

bye, bye

Posted by stefano on 29 August 2002 (Comment Permalink)

Is there any way of opening the default email client other than using anchor tag..
i mean onload event of a window or body..

please help me if anyone knows how to..
thanks friends,

Rajeev

Posted by Rajeev on 23 October 2002 (Comment Permalink)

This discussion is now closed. My thanks to everyone who contributed.

© Copyright 2007 Jonathon Delacour