首页 文章

如何标记电话号码?

提问于
浏览
440

我想在HTML文档中将电话号码标记为可调用链接 . 我已经阅读the microformats approach,我知道, tel: 计划将是标准的,但实际上没有实施 .

据我所知,Skype定义了 skype:callto: ,后者已经获得了一些人气 . 我认为,其他公司有其他计划或跳上 callto: 列车 .

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

奖金问题:有没有人知道紧急号码的并发症,如美国的911或德国的110?

干杯,

Update: Microsoft NetMeeting在WinXP下采用 callto: 方案 . This question建议,Microsoft Office Communicator将处理 tel: 方案,但不处理 callto: 方案 . 太棒了,雷德蒙!

Update 2: 两年半以后了 . 它似乎归结为您想要对数字做什么 . 在移动环境中, tel: 是要走的路 . 如果您认为您的用户更多是Skype用户( callto: ),或者更有可能安装Google Voice( tel: )之类的东西,那么定位桌面就取决于您 . 我的个人意见是,如果有疑问,请使用 tel: (符合@Sidnicious的回答) .

Update 3: 用户@ rybo111指出,Chrome中的Skype同时也加入了 tel: 潮流 . 我无法验证这一点,因为没有任何机器都在手边,但如果这是真的,这意味着我们终于有了一个赢家:

tel:

14 回答

  • 0

    这对我有用:

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

    <a href="tel:1500100900">
    

    2.在未检测到移动浏览器时替换它,对于Skype:

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

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

    我把它放在函数 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 )
        );
    }
    
  • 3

    tel: 计划是used in the late 1990s并于2000年初记录RFC 2806(2004年更为彻底的RFC 3966已经废弃)和continues to be improved . 在iPhone上支持 tel: 并不是一个武断的决定 .

    callto: ,虽然受Skype支持, is not a standard 应该避免,除非专门针对Skype用户 .

    我?我刚刚开始在你的页面上包含正确形成的 tel: URI(没有嗅探用户代理)并等待世界其他地方的手机赶上:) .

    Example

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

    我的测试结果:

    callto:

    • 诺基亚浏览器:没有任何反应

    • Google Chrome:要求运行Skype来拨打该号码

    • Firefox:要求选择一个程序来拨打该号码

    • IE:要求运行Skype来拨打该号码

    tel:

    • 诺基亚浏览器:工作

    • 谷歌浏览器:没有任何反应

    • Firefox:"Firefox doesnt know how to open this url"

    • IE:找不到网址

  • 10

    由于skype默认支持 callto: (在Skype设置中设置),而其他人也支持它,我建议使用 callto: 而不是 skype: .

  • 44

    虽然Apple建议在他们的Mobile Safari文档中使用 tel: ,但目前(iOS 4.3)它只接受 callto: . 所以我建议在通用网站上使用 callto: ,因为它适用于Skype和iPhone,我希望它也适用于Android手机 .

    更新(2013年6月)

    这仍然是决定您希望您的网页提供什么的问题 . 在我的网站上,我提供 tel:callto: 链接(后者标记为Skype),因为Mac上的桌面浏览器不会对 tel: 链接执行任何操作,而移动Android不会对 callto: 链接执行任何操作 . 即使是使用Google Talk插件的Google Chrome也无法响应 tel: 链接 . 尽管如此,我还是希望在桌面上提供这两个链接,以防有人因为在他们的计算机上使用 tel: 链接而遇到麻烦 .

    如果网站设计规定我只提供一个链接,我会使用 tel: 链接,我会尝试在桌面浏览器上更改为 callto: .

  • 2

    我使用正常的 <a href="tel:+123456">12 34 56</a> 标记,并通过 pointer-events: none; 使桌面用户无法点击这些链接

    a[href^="tel:"] {
        text-decoration: none;
    }
    .no-touch a[href^="tel:"] {
        pointer-events: none;
        cursor: text;
    }
    

    对于不支持指针事件(IE <11)的浏览器,可以使用JavaScript阻止点击(示例依赖于Modernizr和jQuery):

    if(!Modernizr.touch) {
        $(document).on('click', '[href^="tel:"]', function(e) {
            e.preventDefault();
            return false;
        });
    }
    
  • -1

    我保留这个答案是为了"historic"目的,但不要上面的答案和我的更新2 .

    因为它看起来像是callto和tel之间的平局,所以我想提出一个可能的解决方案,希望你的评论会让我重新回到光明之路上;-)

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

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

    然后,如果客户端是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:"));
          }
        }
      }
    };
    

    对此解决方案有任何异议?我应该从 tel: 开始吗?

  • 71

    我用 tel: 作为我的项目 .

    它适用于Chrome,Firefox,IE9和8,Chrome移动设备以及索尼爱立信智能手机上的移动浏览器 .

    但是 callto: 没有在移动浏览器中工作 .

  • 3

    我会使用 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:");
        }
    });
    

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

    要禁止不支持的协议的错误页面,链接将定位到新的隐藏iframe .

    不幸的是,如果网址已成功加载到iframe中,似乎无法检查 . 似乎没有触发错误事件 .

  • 8

    使用jQuery,用相应的 callto:tel: 方案替换页面上的所有美国电话号码 .

    // create a hidden iframe to receive failed schemes
    $('body').append('<iframe name="blackhole" style="display:none"></iframe>');
    
    // decide which scheme to use
    var scheme = (navigator.userAgent.match(/mobile/gi) ? 'tel:' : 'callto:');
    
    // replace all on the page
    $('article').each(function (i, article) {
        findAndReplaceDOMText(article, {
            find:/\b(\d\d\d-\d\d\d-\d\d\d\d)\b/g,
            replace:function (portion) {
                var a = document.createElement('a');
                a.className = 'telephone';
                a.href = scheme + portion.text.replace(/\D/g, '');
                a.textContent = portion.text;
                a.target = 'blackhole';
                return a;
            }
        });
    });
    

    感谢@jonas_jonas的想法 . 需要优秀的findAndReplaceDOMText function .

  • 21

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

  • 2

    RFC3966定义了电话号码的IETF标准URI,即'tel:' URI . 's the standard. There'没有类似的标准指定'callto:',这是Skype在平台上的一种特殊约定,允许注册URI处理程序来支持它 .

  • 2

    最好的选择是从tel开始:适用于所有手机

    然后输入此代码,该代码仅在桌面上运行,并且仅在单击链接时运行 .

    我正在使用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:'));
        });
    }
    

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

    tel:适用于所有手机,用号码打开拨号器

    callto:在您的计算机上工作,从firefox,chrome连接到skype

  • 456

    Mobile Safari(iPhone和iPod Touch)使用 tel: 方案 .

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

相关问题