Created
January 8, 2015 12:07
-
-
Save devbyray/0e12514b33c92b12af69 to your computer and use it in GitHub Desktop.
Function to check if Mobile Device (Android, WebOS, iPhone, iPad, iPod (or iOS), Windows Phone, SymbianOS, RIM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
var useragent = navigator.userAgent; | |
function deviceOS() { | |
if(useragent.match(/Android/i)) { | |
return 'android'; | |
} else if(useragent.match(/webOS/i)) { | |
return 'webos'; | |
} else if(useragent.match(/iPhone/i)) { | |
return 'iphone'; | |
} else if(useragent.match(/iPod/i)) { | |
return 'ipod'; | |
} else if(useragent.match(/iPad/i)) { | |
return 'ipad'; | |
} else if(useragent.match(/Windows Phone/i)) { | |
return 'windows phone'; | |
} else if(useragent.match(/SymbianOS/i)) { | |
return 'symbian'; | |
} else if(useragent.match(/RIM/i) || useragent.match(/BB/i)) { | |
return 'blackberry'; | |
} else { | |
return 'no-device'; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment