Last active
December 25, 2015 07:49
-
-
Save mturnwall/6941819 to your computer and use it in GitHub Desktop.
A simple function to determine if a device is iPad, iPhone, or Android. The version of the OS is also returned.
This file contains hidden or 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
var deviceIs = (function () { | |
var userAgent = navigator.userAgent, | |
device = { | |
type: (userAgent.match(/iphone|android|ipad/i)) ? userAgent.match(/iphone|android|ipad/i)[0] : false, | |
fullVersion: false, | |
majorVersion: false | |
}; | |
if (device.type) { | |
device.fullVersion = userAgent.match(/(OS|android)\s+([\d(\_|\.)]+)/i)[0].replace(/_/g,'.'); | |
device.majorVersion = device.fullVersion.match(/[0-9]/)[0]; | |
} | |
return device; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example of what the
deviceIs
properties will look like: