Created
May 22, 2024 06:34
-
-
Save devstar0209/4da581c9bb54e4ecb00b95a228fd2770 to your computer and use it in GitHub Desktop.
Get platform of a web browser
This file contains hidden or 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
function getPlatform() { | |
const userAgent = navigator.userAgent || navigator.vendor || window.opera; | |
// Check for iOS | |
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { | |
return 'iOS'; | |
} | |
// Check for Android | |
if (/android/i.test(userAgent)) { | |
return 'Android'; | |
} | |
// Check for desktop | |
if (/Mac|Win|Linux/.test(navigator.platform)) { | |
return 'Desktop'; | |
} | |
// Default to unknown | |
return 'unknown'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment