Created
October 5, 2017 18:54
-
-
Save diligasi/680642ea2a84eddc56e3056a1d87e63f to your computer and use it in GitHub Desktop.
Uses JavaScript to check if the device accessing the system is mobile one and, if so, which OS (Android, IOS, etc ...)
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
const isMobile = { | |
getUserAgent: function() { | |
return navigator.userAgent; | |
}, | |
Android: function() { | |
return /Android/i.test(isMobile.getUserAgent()) && !isMobile.Windows(); | |
}, | |
BlackBerry: function() { | |
return /BlackBerry|BB10|PlayBook/i.test(isMobile.getUserAgent());; | |
}, | |
iPhone: function() { | |
return /iPhone/i.test(isMobile.getUserAgent()) && !isMobile.iPad() && !isMobile.Windows(); | |
}, | |
iPod: function() { | |
return /iPod/i.test(isMobile.getUserAgent()); | |
}, | |
iPad: function() { | |
return /iPad/i.test(isMobile.getUserAgent()); | |
}, | |
iOS: function() { | |
return (isMobile.iPad() || isMobile.iPod() || isMobile.iPhone()); | |
}, | |
Opera: function() { | |
return /Opera Mini/i.test(isMobile.getUserAgent()); | |
}, | |
Windows: function() { | |
return /Windows Phone|IEMobile|WPDesktop/i.test(isMobile.getUserAgent()); | |
}, | |
KindleFire: function() { | |
return /Kindle Fire|Silk|KFAPWA|KFSOWI|KFJWA|KFJWI|KFAPWI|KFAPWI|KFOT|KFTT|KFTHWI|KFTHWA|KFASWI|KFTBWI|KFMEWI|KFFOWI|KFSAWA|KFSAWI|KFARWI/i.test(isMobile.getUserAgent()); | |
}, | |
any: function() { | |
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment