a href tel and standard browsers

ggdx picture ggdx · Jan 22, 2013 · Viewed 8k times · Source

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.

Answer

Ricardo Ortega Maga&#241;a picture Ricardo Ortega Magaña · Jan 22, 2013

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