【问题标题】:a href tel and standard browsersa href 电话和标准浏览器
【发布时间】:2013-01-05 13:19:42
【问题描述】:

我有一个项目需要通过电话号码使用<a href="tel:123456">(123456 不是号码),但是这将导致除移动浏览器之外的所有设备出现问题,因为无法解释tel: 位。

我曾尝试在浏览器宽度为

任何关于如何克服这个问题的想法都将不胜感激。我正在使用 PHP、jQuery 和 JavaScript。

【问题讨论】:

标签: php jquery html anchor tel


【解决方案1】:

您想检测用户是否有移动浏览器? 这可能会有所帮助:

http://jquerybyexample.blogspot.com/2012/03/detect-mobile-browsers-using-jquery.html

【讨论】:

  • 谢谢 Zim。除了 iPhone 也可以使用,所以我选择了上面的 Ricardo。
【解决方案2】:

用 PHP 检测它是否是移动代理: http://www.000webhost.com/forum/scripts-code-snippets/27404-php-extremely-simple-way-check-if-mobile-browser.html

   <?php
        if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
           echo '<a href="tel:123456">';
        }else{
           echo 'You are not in a mobile';
        }
   ?>

【讨论】:

    【解决方案3】:

    由于您使用的是 PHP,我可以推荐 php-mobile-detect 类。您可以满足单个设备/操作系统/浏览器的需求,或者简单地使用 isMobile()isTablet() 作为一个包罗万象的东西。

    我通常会这样做:

    include './includes/Mobile_Detect.php';
    $detect = new Mobile_Detect;
    
    if ( $detect->isMobile() or $detect->isTablet() ){
        $phone='<a href="tel:+12345678910">1-234-567-8910</a>';
    } else {
        $phone='1-234-567-8910';
    }
    

    然后我只需 &lt;?php echo $phone;?> 在我需要的任何地方,它都非常有用!通过使用 PHP 而不是 javascript,这意味着检测是在服务器端完成的,因此最终用户需要下载的内容更少(如 jQuery 和额外的脚本)。

    设备库会经常更新,因此值得每隔一段时间检查一下GitHub page

    【讨论】:

      【解决方案4】:

      试试下面这个:

      语法:调用

      <a href="callto://9566603286">9566603286</a>
      
       <?php
          if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
             echo '<a href="callto://9566603286">9566603286</a>';
          }else{
             echo 'You are not in a mobile';
          }
       ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-31
        相关资源
        最近更新 更多