处理电话:anchor
我有一个电话号码的锚点。在手机上很棒。在带有 Skype 或 Google Voice 的桌面上,效果很好。问题出在桌面上,他们不知道如何处理这个问题。
我应该怎么办?检测它是否不是移动设备并更改链接?我仍然希望显示链接,只是 URL 不同。
有更好的办法吗?如果没有,我如何在 JavaScript 中检测移动设备以便更改 href 属性?
谢谢。
I have an anchor to a telephone number. On phones is great. On desktops with Skype or Google Voice it's good. The problem is on desktops that just don't know how to deal with that.
What should I do? Detect if it's not mobile and change the link? I still want the link to show, just the URL to be different.
Is there a better way? If not, how do I detect mobile in JavaScript in order to change the href attribute?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要检测浏览器是否从 JavaScript 中的移动设备启动:http://detectmobilebrowser.com/
然后您可以检测JavaScript 中使用正则表达式的电话号码,例如其中之一: http://www.regxlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7
最后重写链接:aLink.href="..."
网络浏览器负责启动某个链接的关联应用程序,我猜 Skype 正在桌面中注册电话号码。恐怕您无法从网页上执行任何操作。
To detect if the browser is launching from a mobile in JavaScript: http://detectmobilebrowser.com/
Then you can detect a phone number in JavaScript using a regular expression, such as one of those: http://www.regxlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7
And finally rewrite the link: aLink.href="..."
The web-browser is responsible for launching the associated application for a certain link and I guess skype is registering for the phone numbers in the desktop. You can't do anything from the web-page I'm afraid.
我发现解决这个问题的方法是使用两个单独的链接,尽管我使用的是 Foundation 4 框架,所以不确定这是否在其他响应式框架中可用。
我将要使用“tel”锚点的链接指定为 .hide-for-large 类,将联系页面的链接指定为 .hide-for-small 类。这可以有效地隐藏并显示相应的链接,具体取决于检测到的视口宽度。
我确信像 Bootstrap 这样的东西也会有类似的类。当然,如果你不是;
The way that I've found to get around this is to use two separate links, although I am using the Foundation 4 framework, so not sure if this is available in other responsive frameworks.
I give the link that I want to use the "tel" anchor the class .hide-for-large, and the link to the contact page a class of .hide-for-small. This effectively hides and dhows the respective link, dependent upon the detected viewport width.
I'm sure there will be a similar class in something like Bootstrap. Of course, if you aren;t