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.
Asked
Active
Viewed 237 times
0
-
yes they detect if a device is touch only by touching It, because you have touch screens for desktops, tv's etc and im not sure if you can detect those another way, unless you can check the browsers user agent for that. Usualy it just details the dimensions of the screen not type. If you want to detect a mobile device then check here -- http://stackoverflow.com/questions/22386837/detect-tablet-and-smartphone – Tasos Mar 29 '16 at 17:18
-
so the only method to detect touch devces is touching them?Instead the better method to detect a mobile device is the method that you have linked? – Merecol Mar 29 '16 at 19:42
-
yes, how would you know when you have a Touch tv monitor. And yes on mobile devices the browser knows the OS so you go by that code in the link – Tasos Mar 30 '16 at 19:25
1 Answers
0
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
}
}

Andreas
- 23,610
- 6
- 30
- 62