Html 如何标记电话号码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1164004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:21:50  来源:igfitidea点击:

How to mark-up phone numbers?

htmlmarkupurl-schemephone-number

提问by Boldewyn

I want to mark up a phone number as callable link in an HTML document. I have read the microformats approach, and I know, that the tel:scheme would be standard, but is quite literally nowhere implemented.

我想在 HTML 文档中将电话号码标记为可调用链接。我已经阅读了微格式方法,并且我知道该tel:方案将是标准的,但实际上没有实现。

Skype defines, as far as I know, skype:and callto:, the latter having gained some popularity. I assume, that other companies have either other schemes or jump on the callto:train.

据我所知,Skype 定义了skype:callto:,后者已经获得了一些普及。我假设,其他公司要么有其他计划,要么跳上callto:火车。

What would be a best practice to mark-up a phone number, so that as many people as possible with VoIP software can just click on a link to get a call?

标记电话号码的最佳做法是什么,以便尽可能多的人使用 VoIP 软件只需单击链接即可接听电话?

Bonus question: Does anyone know about complications with emergency numbers such as 911 in US or 110 in Germany?

额外问题:有谁知道紧急号码的并发症,例如美国的 911 或德国的 110?

Cheers,

干杯,

Update:Microsoft NetMeeting takes callto:schemes under WinXP. This questionsuggests, that Microsoft Office Communicator will handle tel:schemes but not callto:ones. Great, Redmond!

更新:Microsoft NetMeetingcallto:在 WinXP 下采用方案。这个问题表明,Microsoft Office Communicator 将处理tel:方案而不是方案callto:。太好了,雷德蒙德!

Update 2:Two and a half years later now. It seems to boil down to what you want to do with the number. In mobile context, tel:is the way to go. Targeting desktops it's up to you, if you think your users are more Skype people (callto:) or will more likely have something like Google Voice (tel:) installed. My personal opinion is, when in doubt use tel:(in line with @Sidnicious' answer).

更新 2:两年半后的现在。这似乎归结为你想用这个数字做什么。在移动环境中,这tel:是要走的路。如果您认为您的用户更多是 Skype 用户 ( callto:) 或者更有可能tel:安装Google Voice ( )之类的东西,则由您决定是否针对台式机。我个人的意见是,在有疑问时使用tel:(与@Sidnicious 的回答一致)。

Update 3:User @rybo111 noted, that Skype in Chrome has meanwhile jumped on the tel:bandwagon. I cannot verify this, because no machine with both at hand, but if it's true, it means we have finally a winner here: tel:

更新 3:用户@rybo111 指出,Chrome 中的 Skype 同时也tel:赶上了潮流。我无法验证这一点,因为手头上没有机器,但如果这是真的,这意味着我们终于有了赢家:tel:

回答by s4y

The tel:scheme was used in the late 1990sand documented in early 2000 with RFC 2806(which was obsoleted by the more-thorough RFC 3966in 2004) and continues to be improved. Supporting tel:on the iPhone was not an arbitrary decision.

tel:方案在 1990 年代后期使用,并在 2000 年初与RFC 2806(在 2004 年被更全面的RFC 3966淘汰)一起记录,并继续得到改进tel:在 iPhone 上提供支持并不是一个武断的决定。

callto:, while supported by Skype, is not a standardand should be avoided unless specifically targeting Skype users.

callto:,虽然 Skype 支持,但不是标准,除非专门针对 Skype 用户,否则应避免使用。

Me? I'd just start including properly-formed tel:URIs on your pages (without sniffing the user agent) and wait for the rest of the world's phones to catch up :) .

我?我只是开始tel:在您的页面上包含格式正确的URI(不嗅探用户代理),然后等待世界其他地方的电话赶上:)。

Example:

示例

<a href="tel:+18475555555">1-847-555-5555</a>

回答by Murat

My test results:

我的测试结果:

callto:

拨电至:

  • Nokia Browser: nothing happens
  • Google Chrome: asks to run skype to call the number
  • Firefox: asks to choose a program to call the number
  • IE: asks to run skype to call the number
  • 诺基亚浏览器:没有任何反应
  • 谷歌浏览器:要求运行 Skype 拨打电话
  • Firefox:要求选择一个程序来呼叫该号码
  • IE:要求运行 Skype 拨打电话

tel:

电话:

  • Nokia Browser: working
  • Google Chrome: nothing happens
  • Firefox: "Firefox doesnt know how to open this url"
  • IE: could not find url
  • 诺基亚浏览器:工作
  • 谷歌浏览器:没有任何反应
  • 火狐:“火狐不知道如何打开这个网址”
  • IE:找不到网址

回答by mordy

The best bet is to start off with tel: which works on all mobiles

最好的办法是从电话开始:它适用于所有手机

Then put in this code, which will only run when on a desktop, and only when a link is clicked.

然后输入这段代码,它只会在桌面上运行,并且只有在点击链接时才会运行。

I'm using http://detectmobilebrowsers.com/to detect mobile browsers, you can use whatever method you prefer

我正在使用http://detectmobilebrowsers.com/来检测移动浏览器,您可以使用任何您喜欢的方法

if (!jQuery.browser.mobile) {
    jQuery('body').on('click', 'a[href^="tel:"]', function() {
            jQuery(this).attr('href', 
                jQuery(this).attr('href').replace(/^tel:/, 'callto:'));
    });
}

So basically you cover all your bases.

所以基本上你涵盖了所有的基础。

tel: works on all phones to open the dialer with the number

电话:适用于所有电话以打开带有号码的拨号器

callto: works on your computer to connect to skype from firefox, chrome

callto:可在您的计算机上从 Firefox、Chrome 连接到 Skype

回答by rymo

As one would expect, WebKit's support of tel:extends to the Android mobile browser as well - FYI

正如人们所料,WebKit 的支持也tel:扩展到了 Android 移动浏览器 - 仅供参考

回答by Boldewyn

I keep this answer for "historic" purpose but don't recommend it anymore. See @Sidnicious' answer above and my Update 2.

我出于“历史性”目的保留此答案,但不再推荐它。请参阅上面的@Sidnicious' 答案和我的更新 2。

Since it looks like a draw between callto and tel guys, I want to throw in a possible solution in the hope, that your comments will bring me back on the way of light ;-)

由于这看起来像是 callto 和 tel 人之间的平局,我想提出一个可能的解决方案,希望您的评论能让我回到光明的道路上 ;-)

Using callto:, since most desktop clients will handle it:

使用callto:,因为大多数桌面客户端都会处理它:

<a href="callto:0123456789">call me</a>

Then, if the client is an iPhone, replace the links:

然后,如果客户端是 iPhone,请替换链接:

window.onload = function () {
  if (navigator.userAgent.match (/iPhone/i)) {
    var a = document.getElementsByTagName ("a");
    for (var i = 0; i < a.length; i++) {
      if (a[i].getAttribute ('href').search (/callto:/i) === 0) {
        a[i].setAttribute ('href', a[i].getAttribute ('href').replace (/^callto:/, "tel:"));
      }
    }
  }
};

Any objections against this solution? Should I preferably start from tel:?

对此解决方案有任何异议吗?我最好从tel:?

回答by Jan Aagaard

Mobile Safari (iPhone & iPod Touch) use the tel:scheme.

移动 Safari(iPhone 和 iPod Touch)使用该tel:方案。

How do I dial a phone number from a webpage on iPhone?

如何从 iPhone 上的网页拨打电话号码?

回答by Leroy Jenkins

RFC3966defines the IETF standard URI for telephone numbers, that is the 'tel:' URI. That's the standard. There's no similar standard that specifies 'callto:', that's a particular convention for Skype on platforms where is allows registering a URI handler to support it.

RFC3966定义了电话号码的 IETF 标准 URI,即“tel:”URI。这就是标准。没有指定“callto:”的类似标准,这是Skype 在允许注册URI 处理程序以支持它的平台上的特定约定。

回答by devein

this worked for me:

这对我有用:

1.make a standards compliant link:

1.制作符合标准的链接:

        <a href="tel:1500100900">

2.replace it when mobile browser is not detected, for skype:

2.当没有检测到移动浏览器时替换它,对于Skype:

$("a.phone")
    .each(function()
{ 
  this.href = this.href.replace(/^tel/, 
     "callto");
});

Selecting link to replace via class seems more efficient. Of course it works only on anchors with .phoneclass.

选择通过类替换的链接似乎更有效。当然,它只适用于带.phone类的锚点。

I have put it in function if( !isMobile() ) { ...so it triggers only when detects desktop browser. But this one is problably obsolete...

我已经把它放在函数中,if( !isMobile() ) { ...所以它只在检测到桌面浏览器时触发。但是这个可能已经过时了......

function isMobile() {
    return (
        ( navigator.userAgent.indexOf( "iPhone" ) > -1 ) ||
        ( navigator.userAgent.indexOf( "iPod" ) > -1 ) ||
        ( navigator.userAgent.indexOf( "iPad" ) > -1 ) ||
        ( navigator.userAgent.indexOf( "Android" ) > -1 ) ||
        ( navigator.userAgent.indexOf( "webOS" ) > -1 )
    );
}

回答by jonas_jonas

I would use tel:(as recommended). But to have a better fallback/not display error pages I would use something like this (using jquery):

我会使用tel:(按照推荐)。但是为了有更好的回退/不显示错误页面,我会使用这样的东西(使用 jquery):

// enhance tel-links
$("a[href^='tel:']").each(function() {
    var target = "call-" + this.href.replace(/[^a-z0-9]*/gi, "");
    var link = this;

    // load in iframe to supress potential errors when protocol is not available
    $("body").append("<iframe name=\"" + target + "\" style=\"display: none\"></iframe>");
    link.target = target;

    // replace tel with callto on desktop browsers for skype fallback
    if (!navigator.userAgent.match(/(mobile)/gi)) {
        link.href = link.href.replace(/^tel:/, "callto:");
    }
});

The assumption is, that mobile browsers that have a mobile stamp in the userAgent-string have support for the tel:protocol. For the rest we replace the link with the callto:protocol to have a fallback to Skype where available.

假设是,在 userAgent 字符串中具有移动标记的移动浏览器支持该tel:协议。对于其余部分,我们用callto:协议替换链接,以便在可用的情况下回退到 Skype。

To suppress error-pages for the unsupported protocol(s), the link is targeted to a new hidden iframe.

为了抑制不受支持的协议的错误页面,链接被定位到一个新的隐藏 iframe。

Unfortunately it does not seem to be possible to check, if the url has been loaded successfully in the iframe. It's seems that no error events are fired.

不幸的是,似乎无法检查 url 是否已在 iframe 中成功加载。似乎没有触发任何错误事件。

回答by fuma

I used tel:for my project.

我用于tel:我的项目。

It worked in Chrome, Firefox, IE9&8, Chrome mobile and the mobile Browser on my Sony Ericsson smartphone.

它适用于 Chrome、Firefox、IE9&8、Chrome 移动版和我索尼爱立信智能手机上的移动浏览器。

But callto:did not work in the mobile Browsers.

callto:在移动浏览器中不起作用。