Skip to content

Instantly share code, notes, and snippets.

@stevenbeales
Created February 12, 2019 02:57
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 stevenbeales/381244a795c4dd8a2146ef3affbe6cd2 to your computer and use it in GitHub Desktop.
Save stevenbeales/381244a795c4dd8a2146ef3affbe6cd2 to your computer and use it in GitHub Desktop.
const detectDeviceType = () =>
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
? 'Mobile'
: 'Desktop';
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