Main Content

Web page to telephone calls / links using an iPhone

Archive - Originally posted on "The Horse's Mouth" - 2010-03-08 12:59:19 - Graham Ellis

Would you like people who visit your web site from their iPhone you be able to just click on your number and call you? Well - they can; the iPhone Safari browser recognized phone numbers and turns them into telephone links. But you might want a bit more control as the web site author ...

• To add a link that phones you, where the link is NOT a phone number, you can use a link of the form:
  <a href="tel:+44-1225-708225">

• To suppress a link from a phone number, I have found that putting a start and end span tag in the middle does the trick:
  0800 0<span></span>43 8225

• To link to a different number that the one shown on your page, simply add your own link around the number:
  <a href="tel:+44-1225-708225">01225 708225</a>
This is potentially open to abuse (eg. offer a freephone number but link to a similar number that costs), but my example is a sensible one as it lets me display my number as expected by my UK customers, but then converts it so that the link will work internationally (worldwide) if someone follows it from overseas.

The tel: protocol isn't supported by all browsers, though, and if you want to avoid offering links that do strange things when selected on your computer (as opposed to your phone), you'll need to recognise the browser and only provide the links where it's appropriate.

Here's a simple example of how you might to this (in PHP):

• Recongise if the phone is an iPhone:
  <?php $iphone = preg_match("/iPhone/",$_SERVER[HTTP_USER_AGENT]); ?>

• And if it is an iPhone, send an extra link:
  <?php if ($iphone) print ('<a href="tel:+44-1225-708225">'); ?>
then add in the link content such as an image, then:
  <?php if ($iphone) print ("</a>"); ?>

Do you have Flash in your web page? And do you want your application to work well on the iPhone? The default iPhone browser does not support Flash ... there are various ways to get an iPhone to render Flash ... but rather than put your potential customer to the trouble, why not use the PHP above and send out an alternative?


I like to provide a "try it here" page with all my Blogs, but it this case I don't think I will - Lisa would be really happy with me if she got a lot of "just testing" phone calls ... however, on the Well House Consultants home page and on the Well House Manor Home page, clicking on the big text than announces our name will offer you a call to us. Please use it if you would like to book a weekend away, or a course ;-)

If you're not familiar with PHP, have a look at our courses - we offer a variety of curricula, depending on your background and on what you want to be able to do with the language.