簡體   English   中英

href電話和標准瀏覽器

[英]a href tel and standard browsers

我有一個項目,要求在電話號碼上輸入<a href="tel:123456"> (不是123456),但這會導致無法解釋tel:位,從而導致除移動瀏覽器以外的所有問題。

當瀏覽器寬度小於1000px時,我嘗試使用jQuery添加href屬性,但這是一種非常不可靠的方法(平板電腦的分辨率也有限)。

任何有關如何克服這一點的想法將不勝感激。 我正在使用PHP,jQuery和JavaScript。

使用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';
        }
   ?>

由於您使用的是PHP,因此我建議您使用php-mobile-detect類。 您可以迎合各個設備/操作系統/瀏覽器的需求,或者簡單地使用isMobile()isTablet()作為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';
}

然后我只要在需要的地方<?php echo $phone ;?>就可以了! 通過使用PHP而不是javascript,這意味着檢測是在服務器端完成的,因此最終用戶的下載量減少了(例如jQuery和其他腳本)。

設備庫經常更新,因此值得經常檢查GitHub頁面

您想檢測用戶是否具有移動瀏覽器? 這可能會有所幫助:

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

請嘗試以下一種方法:

Syntex:callto

<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';
    }
 ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM