Last active
July 7, 2017 19:47
-
-
Save pndparade/6ff3377f087e1013c487beb64f85c0de to your computer and use it in GitHub Desktop.
Determine the mobile operating system
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
| /** | |
| * Determine the mobile operating system. | |
| * This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'. | |
| * | |
| * @returns {String} | |
| */ | |
| function getMobileOperatingSystem() { | |
| var userAgent = navigator.userAgent || navigator.vendor || window.opera; | |
| // Windows Phone must come first because its UA also contains "Android" | |
| if (/windows phone/i.test(userAgent)) { | |
| return "Windows Phone"; | |
| } | |
| if (/android/i.test(userAgent)) { | |
| return "Android"; | |
| } | |
| // iOS detection from: http://stackoverflow.com/a/9039885/177710 | |
| if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { | |
| return "iOS"; | |
| } | |
| return "unknown"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment