Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Check if the device is an Android Tablet / iPad. Also checks if it is a phone or a desktop. Mainly written to differentiate between tablets and mobile phones.
function getUserAgent(){
var ua = navigator.userAgent.toLowerCase();
if((ua.indexOf("iphone") !== -1) || ((ua.indexOf("mobile") !== -1) && (ua.indexOf("android") !== -1))){
//The device is a mobile.
}
else if((ua.indexOf("ipad") !== -1) || (ua.indexOf("android") !== -1)){
//The device is a tablet.
}
else{
//Desktop or unrecogonised device.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment