Created
September 10, 2022 13:13
-
-
Save quantumwebco/12191f073f4b37fc83d1f635cecf3a03 to your computer and use it in GitHub Desktop.
Get platform and standalone mode
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
isInStandaloneMode() { | |
return (window.matchMedia("(display-mode: standalone)").matches) || | |
(("standalone" in window.navigator) && (window.navigator.standalone)); | |
} | |
isMac() { | |
return /(macintosh|macintel|macppc|mac68k|macos)/i.test(window.navigator.userAgent.toLowerCase()); | |
} | |
isIos() { | |
return /iphone|ipad|ipod/i.test(window.navigator.userAgent.toLowerCase()); | |
} | |
platform() { | |
let userAgent = window.navigator.userAgent.toLowerCase(), | |
macosPlatforms = /(macintosh|macintel|macppc|mac68k|macos)/i, | |
windowsPlatforms = /(win32|win64|windows|wince)/i, | |
iosPlatforms = /(iphone|ipad|ipod)/i; | |
if (macosPlatforms.test(userAgent)) { | |
return "macos"; | |
} | |
if (iosPlatforms.test(userAgent)) { | |
return "ios"; | |
} | |
if (windowsPlatforms.test(userAgent)) { | |
return "windows"; | |
} | |
if (/android/.test(userAgent)) { | |
return "android"; | |
} | |
if (/linux/.test(userAgent)) { | |
return "linux"; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment