使用 jQTouch 时,我无法从 Mobile Safari 获取用于打开邮件应用程序的 mailto 链接。可能出什么问题了?

发布于 2024-08-23 00:25:29 字数 774 浏览 5 评论 0原文

我正在使用 jQTouch 开发 iPhone Web 应用程序,它包含一个简单的 mailto: 链接到有效的电子邮件地址,点击该地址后应该会启动 iPhone 邮件应用程序,但事实并非如此。

如果我在 Mobile Safari 中访问包含完全相同链接的“正常”网页,然后点击它,我会得到预期的结果:邮件应用程序会弹出,并在“收件人”字段中显示正确的电子邮件地址。

这是链接 HTML(地址已更改),以防万一我发疯并犯了一个愚蠢的错误,但它看起来完全没问题:

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

有人在使用 jQTouch 时遇到过这个吗?或者有人至少可以建议一种我可以调试这个的方法吗?当我点击非工作链接时,它会闪烁红色(活动链接状态),并且绝对不会发生其他情况。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

耶耶耶 2024-08-30 00:25:30

我再次查看了 jQTouch 演示包中的示例代码,发现他们在电子邮件链接中添加了 target="_blank" 属性。

我对我的链接执行了此操作,它开始工作(弹出邮件客户端窗口)。但是,标准网页中的链接也可以工作,但是没有 target="_blank" 属性...

我很困惑,但添加该属性似乎如果您的移动页面使用jQTouch,可以解决此问题。

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.

初心未许 2024-08-30 00:25:30

只要使用 target="_blank" 就可以正常工作。

对于那些觉得每次点击mailtotel链接时都会弹出“这将在新页面中打开”的烦人的人(像我一样),您可以这样做编辑

jqtouch.js 并转到第 284 行:

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

现在将此行替换为:

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

在 HTML 上(例如):

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

变为

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

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>
若相惜即相离 2024-08-30 00:25:30

很棒的发现,我也在做同样的事情,直到最近才明白为什么。如果您查看 jqtouch.js rev 109 中的第 161 行和第 284 行,您会发现目标属性“_Blank”将阻止 jqtouch 劫持您的点击事件。它拦截事件,因为这是从一个页面移动到另一个页面的主要机制。

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.

月亮是我掰弯的 2024-08-30 00:25:30

这与 jQTouch 无关,但 mailto: 链接对我也不起作用,要修复它们,我所要做的就是在冒号后添加斜杠。

mailto://[电子邮件受保护]

已收到在这里执行此操作的想法:http://mobiledevelopertips。 com/cocoa/launching-other-apps-within-an-iphone-application.html。奇怪的是,电话连接对我来说工作得很好,没有斜线。

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.

栀梦 2024-08-30 00:25:29

我发现向链接添加 target="_blank" 是有效的 - 除了在某些桌面浏览器上,它会打开一个新的空白窗口并打开电子邮件窗口。诚然,jqtouch 网站通常不会在桌面浏览器上查看,但我不喜欢这种行为。

相反,这就是我所做的:

  • mailto: 链接放入 onclick 事件中,并添加 return false (所以到 # 的实际链接不会触发)
  • 向链接添加了 noHighlight

这是一个示例:

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

然后我修改了主题中的 CSS文件。

之前:

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

之后:

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

我添加 noHighlight 类的原因是,如果没有它,按钮将突出显示并“粘住”,这使得按钮看起来仍然处于某种活动状态。为了解决这个问题,我添加了该类并修改了 CSS,如上所述。

CSS 更改的作用是,如果链接(在 li 内部,又在 ul 内部)具有类 noHighlight,它将不要更改背景或文本颜色。

现在似乎在桌面和移动浏览器上都运行得很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文