3
votes

I am encountering problems with using images instead of plain text as links for mobile Safari on iOS5, tested on device. I have tried three different link protocols, tel: mailto: and http: and describe the problem for each below.

<a href="tel:1234"><img src="images/phone.jpg" alt="" /></a>

Does not work in iOS5, it throws an Cannot Open Page error, but works with text as link.

<a href="mailto:foo@bar.com"><img src="images/mail.jpg" alt="" /></a>

Does work and fires up the mail app.

<a href="http://www.mysite.com"><img src="images/home.jpg" alt="" /></a>

Works as expected.

However, the 'touch-and-hold' event, which pops up with normal text links works differently for images. For mailto links this is New Message/Add to Contacts/Copy/Cancel and for tel links it is Call/Add to Contacts/Copy/Cancel. With image links, the pop-up gives the options Open/Save Image/Copy/Cancel for both the mailto and tel links, with the Open option failing for tel links "because the address is invalid".

For my website, I would like to include my email and phone details, with the ability to mail/call directly, or to add it to the contacts. I found a related and unresolved question here: Dial a number using Phonegap in IPhone

Any help would be greatly appreciated.

Curiously, when saved to the home screen on an iOS device, and ran as a web-app, the touch-and-hold gesture results in no popup at all for the image links, whereas the text links work fine. (To enable a website to be run as a web-app, I added the following code in the head of the page:)

<meta name="apple-mobile-web-app-capable" content="yes" />

Can anybody reproduce this behaviour using the above link, and have clues which versions of iOS may be affected? I tested it on iPodTouch iOS 5.0.1 and iPad iOS 4.3.3. Thanks.

2

2 Answers

1
votes

I noticed this same problem. To work around it, I used a CSS background-image instead of an img tag:

<style type="text/css">
    .tel { 
        width: 102px; 
        height: 32px; 
        display: inline-block; 
        background: url(phone.png); 
    }
</style>

<a class="phone" href="tel:+1-000-000-0000"><span class="tel"></span></a>

Note that I specifically leave no whitespace inside of the a tag because otherwise the iPhone shows it next to the image (it appears for me as an empty underline, but this depends on your own CSS).

0
votes

I can't repro your image link failure on iOS 5.0.1. Specifically, I put the following line into a webpage on apache:

<p>This is a test of a tel link: <a href="tel:2060000000"><img src="/iPodTouch_s4.png"></a></p>

A touch on the graphic brings up the phone dialog, with Cancel and Call options.

Touch-and-hold on the graphic presents Open in Phone, Save Image and Copy; touching Open in Phone brings up the phone dialog, again with Cancel and Call options.

The only way I can reproduce your experience is by mistyping the protocol designator. For example, this reproduces everything you mention (note the 1 instead of lowercase L in the href):

<p>This is a test of a tel link: <a href="te1:2060000000"><img src="/iPodTouch_s4.png"></a></p>

Are you positive there's no mistyping or other issue with the link?