Created
September 8, 2017 19:17
-
-
Save mistercoffee66/b42b8c2f0a01ceb05bbe8fcca7ae5aca to your computer and use it in GitHub Desktop.
quick n dirty user agent tests
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 = () =>{ | |
return ( navigator.userAgent.match(/Android/i) || | |
navigator.userAgent.match(/BlackBerry/i) || | |
navigator.userAgent.match(/iPhone/i) || | |
navigator.userAgent.match(/iPad/i) || | |
navigator.userAgent.match(/iPod/i) || | |
navigator.userAgent.match(/iPhone|iPad|iPod/i) || | |
navigator.userAgent.match(/IEMobile/i) ) | |
} | |
const androidVersion = () => { | |
const ua = navigator.userAgent | |
return ua.indexOf("Android") >= 0 ? | |
parseFloat(ua.slice(ua.indexOf("Android")+8)) : | |
-1 | |
} | |
const isAndroid = () => { | |
const ua = navigator.userAgent | |
return ua.indexOf("Android") >= 0 | |
} | |
export {isMobile, androidVersion, isAndroid} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment