Skip to main content

Figure out if the device is a mobile or a desktop/laptop Using JavaScript

detectDeviceType() this function will return you a string value either "Mobile" or "Desktop".

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

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


See Demo on Codepen :-

See the Pen Figure out if the device is a mobile or a desktop/laptop Using JavaScript by SH20RAJ (@SH20RAJ) on CodePen.

Comments

Random Posts