Created
May 6, 2025 19:58
-
-
Save estevan-ulian/8f1286c76722f755df6cc55180110e5f to your computer and use it in GitHub Desktop.
Verify type of userAgent
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 getDeviceType() { | |
| const ua = navigator.userAgent.toLowerCase(); | |
| const tablet = /ipad|android(?!.*mobile)|tablet|playbook|silk/; | |
| const mobile = /iphone|ipod|android.*mobile|blackberry|bb10|opera mini|windows phone/; | |
| if (tablet.test(ua)) { | |
| return "tablet"; | |
| } | |
| if (mobile.test(ua)) { | |
| return "mobile"; | |
| } | |
| if (window.matchMedia && window.matchMedia("(pointer: coarse) and (max-width: 1024px)").matches) { | |
| return "tablet"; | |
| } | |
| return "desktop"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment