Last active
March 5, 2024 01:32
-
-
Save LukeberryPi/baa8903fce105f012ea3b4d3601c1edd to your computer and use it in GitHub Desktop.
isMobile utils
This file contains 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
export const isTouchable = () => { | |
const userAgent = window.navigator.userAgent; | |
return ( | |
!!userAgent && userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) | |
); | |
}; | |
export const isIphone = () => { | |
return ( | |
!!navigator.platform && | |
/iPad|iPhone|iPod/.test(navigator.platform) | |
); | |
}; | |
export const isMobile = () => { | |
return isTouchable() ? window.outerWidth <= 776 : window.innerWidth <= 776; | |
}; | |
export const isIpad = () => { | |
return ( | |
(/iPad/.test(navigator.platform) || | |
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) && | |
!window.MSStream | |
); | |
}; | |
export const isTablet = () => { | |
return isTouchable() | |
? window.outerWidth <= 1024 && window.outerWidth > 776 | |
: window.innerWidth <= 1024 && window.innerWidth > 776; | |
}; | |
export const isDesktop = () => { | |
return isTouchable() ? window.outerWidth > 1024 : window.innerWidth > 1024; | |
}; | |
export const isSafari = () => { | |
const userAgent = window.navigator.userAgent.toLowerCase(); | |
return userAgent.indexOf('safari') > -1 && userAgent.indexOf('chrome') < 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment