当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Detect touch devices during site's load

问题描述:

How can i detect if a device is touch during site's load?I have seen a lot of functions but if i have understood well they detect if a device is touch only touching It.

网友答案:

This will probably get most of them. But not sure :/

PHP:

$mobile_browser = find_mobile_browser(); // $mobile_browser is now string device brand
function find_mobile_browser()
{
    if(preg_match('/(iphone|ipad|ipod)/i', $_SERVER['HTTP_USER_AGENT']))
    {
        return 'ios';
    }
    elseif (preg_match('/(android)/i', $_SERVER['HTTP_USER_AGENT']))
    {
        return 'android';
    }
    elseif (preg_match('/(webOS)/i', $_SERVER['HTTP_USER_AGENT']))
    {
        return 'webOS';
    }
    else
    {
        return false; //other meaning normal non touch/non mobile
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: