I can't get mailto links to open the Mail app from Mobile Safari when using jQTouch. What could be wrong?
Asked Answered
W

5

12

I'm developing an iPhone web app using jQTouch, and it contains a simple mailto: link to a valid email address, which should launch the iPhone mail application when tapped—but it doesn't.

If I visit a "normal" web page in Mobile Safari which contains the exact same link, and tap on it, I get the expected result: the mail app pops up with the correct email address in the To field.

Here's the link HTML (with the address changed) just in case I'm going nuts and have made a stupid mistake, but it appears perfectly fine:

<p><a href="mailto:[email protected]">[email protected]</a></p>

Has anyone come across this when using jQTouch? Or can anyone at least suggest a way that I can debug this? At the moment when I tap the non-working link it flashes red (the active link state) and absolutely nothing else happens.

Wham answered 23/2, 2010 at 10:48 Comment(2)
what erros does the iphone give?Albertype
None that I can see. Is there some kind of debug console for Mobile Safari?Wham
W
6

I looked again at the example code in the jQTouch demo package and saw that they were adding a target="_blank" attribute to their email link.

I did this to my link, and it began working (popping up the mail client window). However, the link that's in a standard web page works as well, but without the target="_blank" attribute...

I'm puzzled, but adding that attribute seems to solve this problem if your mobile page is using jQTouch.

Wham answered 23/2, 2010 at 15:8 Comment(0)
G
7

I found that adding target="_blank" to the links worked -- except that on some desktop browsers, it opened a new blank window AND opened the email window. Granted, jqtouch sites aren't typically going to be viewed on desktop browsers, but I wasn't fond of that behavior.

Instead, here's what I did:

  • Put the mailto: link in the onclick event and added return false (so actual link to # doesn't fire)
  • Added a noHighlight class to the link

Here is an example:

<a href="#" onclick="window.location='mailto:[email protected]'; return false;" class="noHighlight">Email me</a>

I then modified the CSS in the theme file.

Before:

ul li a.active {
   background: #194fdb url(img/selection.png) 0 0 repeat-x;
   color: #fff;
}

After:

ul li a.active:not(.noHighlight) {
   background: #194fdb url(img/selection.png) 0 0 repeat-x;
   color: #fff;
}

The reason I added the noHighlight class is that without it, the button would get highlighted and would "stick" which made the button look like it was still in some active state. To get around the issue, I added the class and modified the CSS as described above.

What the CSS change does is that if the link (inside of a li which is inside of a ul) has the class noHighlight, it will NOT change the background or text color.

Seems to work great now on both desktop and mobile browsers.

Glossographer answered 8/9, 2010 at 22:20 Comment(1)
Wow, simply changing my tel and mailto links to this javascript version caused them to work better on my iphone/mobile safari. Email hadn't worked, just opened a new blank page, and phone opened new blank page and did call, but now they just do mail or call as they should. Why the original basic links worked so badly is beyond me.Connel
W
6

I looked again at the example code in the jQTouch demo package and saw that they were adding a target="_blank" attribute to their email link.

I did this to my link, and it began working (popping up the mail client window). However, the link that's in a standard web page works as well, but without the target="_blank" attribute...

I'm puzzled, but adding that attribute seems to solve this problem if your mobile page is using jQTouch.

Wham answered 23/2, 2010 at 15:8 Comment(0)
B
2

It works fine just with target="_blank".

For those (like me) who find it annoying to get the "This will open in a new page" popup every time you tap on a mailto or tel link you can do this:

Edit jqtouch.js and go to line 284:

if ($el.attr('target') == '_blank' || $el.attr('rel') == 'external')

Now replace this line by:

if ($el.attr('target') == '_self' || $el.attr('target') == '_blank' || $el.attr('rel') == 'external')

And on the HTML (e.g.):

<a href="tel:+351912345678">Call me</a>

becomes

<a target="_self" href="tel:+351912345678">Call me</a>
Bungalow answered 9/10, 2010 at 18:7 Comment(0)
F
1

Excellent find, I'm doing the same thing and couldn't understand why until recently. If you look round line 161 and 284 in jqtouch.js rev 109 you see that the target attribute "_Blank" will keep jqtouch from hijacking your click event. It is intercepting the event because that is the primary mechanism to move from page to page.

Felonious answered 11/6, 2010 at 3:36 Comment(0)
W
1

This isn't related to jQTouch, but mailto: links weren't working for me either and to fix them, all I had to do was add slashes after the colon.

mailto://[email protected]

Got the idea to do this here: http://mobiledevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html. Strangely enough, telephone links worked fine for me without the slashes.

Whipping answered 19/6, 2012 at 22:34 Comment(2)
On Ubuntu/Chrome with Gmail as mail client, it opens a new mail in Gmail with the target (to) being empty :(Appulse
On Mac with Safari or Chrome, and email client = Apple Mail, a new email opens in Apple Mail but it has a double-slash at the beginning :(Appulse

© 2022 - 2024 — McMap. All rights reserved.