Skip to content

Home

Detect device type

Detects whether the page is being viewed on a mobile device or a desktop.

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

detectDeviceType(); // 'Mobile' or 'Desktop'

More like this

Start typing a keyphrase to see matching snippets.