使用 jQTouch 时,我无法从 Mobile Safari 获取用于打开邮件应用程序的 mailto 链接。可能出什么问题了?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我再次查看了 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.
只要使用 target="_blank" 就可以正常工作。
对于那些觉得每次点击mailto或tel链接时都会弹出“这将在新页面中打开”的烦人的人(像我一样),您可以这样做编辑
jqtouch.js 并转到第 284 行:
现在将此行替换为:
在 HTML 上(例如):
变为
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:
Now replace this line by:
And on the HTML (e.g.):
becomes
很棒的发现,我也在做同样的事情,直到最近才明白为什么。如果您查看 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.
这与 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.
我发现向链接添加
target="_blank"
是有效的 - 除了在某些桌面浏览器上,它会打开一个新的空白窗口并打开电子邮件窗口。诚然,jqtouch 网站通常不会在桌面浏览器上查看,但我不喜欢这种行为。相反,这就是我所做的:
mailto:
链接放入onclick
事件中,并添加 returnfalse
(所以到#
的实际链接不会触发)noHighlight
类这是一个示例:
然后我修改了主题中的 CSS文件。
之前:
之后:
我添加
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:
mailto:
link in theonclick
event and added returnfalse
(so actual link to#
doesn't fire)noHighlight
class to the linkHere is an example:
I then modified the CSS in the theme file.
Before:
After:
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 aul
) has the classnoHighlight
, it will NOT change the background or text color.Seems to work great now on both desktop and mobile browsers.