Detecting the type of browser is simplest by looking at the useragent string. Key words in that string will help detect the browser. UserAgentString.com maintains a thorough list of useragent strings, but the main thing you need to look for are only a few keywords.
For example, the word "blackberry" only ever shows up when browsing from a Blackberry device. Similar with iPad and iPhone. Android devices all show "android" in the useragent string, but they distinguish between tablets and phones by inclusion of the keyword "mobile" for phones.
Here's how we detect Desktops, Phones, and Tablets in our mobile application:
public enum DeviceType
{
Desktop,
Tablet,
Phone
}
public static DeviceType UserAgentToDeviceType(string userAgent)
{
if (userAgent.ToLowerInvariant().Contains("blackberry"))
return DeviceType.Phone;
if (userAgent.ToLowerInvariant().Contains("iphone"))
return DeviceType.Phone;
if (userAgent.ToLowerInvariant().Contains("ipad"))
return DeviceType.Tablet;
if (userAgent.ToLowerInvariant().Contains("android"))
{
if (userAgent.ToLowerInvariant().Contains("mobile"))
return DeviceType.Phone;
else
return DeviceType.Tablet;
}
return DeviceType.Desktop;
}
If you are using something like jQuery Mobile, the site will be customized for mobile appearance regardless of device type, and it will handle differences between the JavaScript engine on different devices.