Search code examples
phpjqueryhtmlanchortel

a href tel and standard browsers


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.


Solution

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