0 points

ES6 snippet - JavaScript - Detect device type


dashboard

Wed Nov 04 2020 08:44:06 GMT+0000 (UTC)

Posted by @julien #javascript

const detectDeviceType = () =>
  /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
    ? 'Mobile'
    : 'Desktop';

// Example
detectDeviceType(); // "Mobile" or "Desktop"
content_copy Copy

https://medium.com/swlh/24-modern-es6-code-snippets-to-solve-practical-js-problems-3609f301859e