demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

Link Oddities: empty links and mailto links

Sometimes you want to give something the appearance of a link, but not actually link to anything. This can be particularly useful when activating a JavaScript function, for example. However, we have a small problem. If you put any text at all inside the quotes of the <a href=""> link, the browser will attempt to find that resource. So what do you do?

The answer is to link to a hash / pound symbol (#). This will give the appearance of a link, but the link won’t actually do anything. For example:

  1. <a href="#">This looks like a link, but it really only appears that way:
  2. it won’t go anywhere when clicked on</a>

In theory you can surround anything with a hypertext reference. The most common things to link are text and images, but under the DOM, a href can be applied to any element - tables, horizontal rules, anything.

If <a> can link to anything, it’s possible to create a link to an eMail that will be automatically created when clicked on by the user:

  1. <a href="mailto:youraddress@yourmailserver.com">

Note that this assumes that the user has an eMail client installed and knows how to use it: be aware that not everyone does (some use a web service like Hotmail or gMail exclusively, for example). Also, this technique does tend to be picked up by “page scrapers” used by stammers to harvest eMail addresses. It's perfectly good, even advisable for a business site, but a better technique is to make a PHP form that will send the contents of a form to an eMail address. Unfortunately, we won’t arrive at that solution until next semester.

If you want to, you can even add a subject line for the eMail:

  1. <a href=”mailto:youraddress@yourmailserver.com?subject=Subject Line Here”>

(Note the use of ? to separate elements in a link: it’s a particularly subtle technique that can be used to great advantage when we get to processing information with PHP.)

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.