Skip to content

Instantly share code, notes, and snippets.

@Alimjanov-Ibragim
Forked from KamaMakh/UA parser
Created June 24, 2022 05:37
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 Alimjanov-Ibragim/8053f768fdf6e93075203814ca0ed575 to your computer and use it in GitHub Desktop.
Save Alimjanov-Ibragim/8053f768fdf6e93075203814ca0ed575 to your computer and use it in GitHub Desktop.
Detect Browser, Engine, OS, CPU, and Device
export const isSafari = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
ua.includes('safari') &&
!ua.includes('crios') &&
!ua.includes('fxios') &&
!ua.includes('android')
);
};
export const isAndroid = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
ua.includes('android') &&
!ua.includes('safari') &&
!ua.includes('ipad') &&
!ua.includes('iphone')
);
};
export const isIOs = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
(ua.includes('iphone') || ua.includes('ipad')) && !ua.includes('android')
);
};
export const getIOSVersion = () => {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
const v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
}
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment