Skip to content

Instantly share code, notes, and snippets.

@mistercoffee66
Created September 8, 2017 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mistercoffee66/b42b8c2f0a01ceb05bbe8fcca7ae5aca to your computer and use it in GitHub Desktop.
Save mistercoffee66/b42b8c2f0a01ceb05bbe8fcca7ae5aca to your computer and use it in GitHub Desktop.
quick n dirty user agent tests
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