Created
February 12, 2019 02:57
-
-
Save stevenbeales/381244a795c4dd8a2146ef3affbe6cd2 to your computer and use it in GitHub Desktop.
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
const detectDeviceType = () => | |
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) | |
? 'Mobile' | |
: 'Desktop'; |
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
detectDeviceType(); // "Mobile" or "Desktop" | |
Detects wether the website is being opened in a mobile device or a desktop/laptop. | |
Use a regular expression to test the navigator.userAgent property to figure out if the device is a mobile device or a desktop/laptop. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment