a href tel and standard browsers
Asked Answered
M

3

2

I have a project that requires <a href="tel:123456"> over the phone number (123456 is not the number) however this will cause an issue for everything except mobile browsers by being unable to interpret the tel: bit.

I have tried to use jQuery to add the href attr when a browser width is <1000px but this is a very unreliable method (tablets also have a limited resolution).

Any ideas on how to overcome this would be greatly appreciated. I am using PHP, jQuery and JavaScript.

Manger answered 22/1, 2013 at 10:28 Comment(1)
One more way to detect mobile device.. ajaxhistory.com/other-scripts/…Dubois
M
3

Detect with PHP if its a mobile agent: 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';
        }
   ?>
Merkle answered 22/1, 2013 at 10:31 Comment(0)
P
2

Since you're using PHP I can recommend the php-mobile-detect class. You can cater to individual devices/OS'es/browsers, or simply use isMobile() or isTablet() as a catch-all.

I usually do something like this:

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

Then I just <?php echo $phone;?> wherever I need it and it works a treat! And by using PHP instead of javascript it means the detection is done server-side, so the end user has less to download (like jQuery and extra scripts).

The library of devices gets updated fairly often, so it's worth checking the GitHub page every so often.

Peerage answered 14/8, 2013 at 16:36 Comment(0)
T
-1

Try this below one :

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';
    }
 ?>
Theocracy answered 19/6, 2014 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.