Skip to content

Instantly share code, notes, and snippets.

@LukeberryPi
Last active March 5, 2024 01:32
Show Gist options
  • Save LukeberryPi/baa8903fce105f012ea3b4d3601c1edd to your computer and use it in GitHub Desktop.
Save LukeberryPi/baa8903fce105f012ea3b4d3601c1edd to your computer and use it in GitHub Desktop.
isMobile utils
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