Q:

Write a JavaScript program to detect whether the website is being opened in a mobile device or a desktop/laptop

0

Write a JavaScript program to detect whether the website is being opened in a mobile device or a desktop/laptop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now