0 votes
in JavaScript by
How do you detect a mobile browser without regexp?

1 Answer

0 votes
by

You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,

function detectmob() {
  if (
    navigator.userAgent.match(/Android/i) ||
    navigator.userAgent.match(/webOS/i) ||
    navigator.userAgent.match(/iPhone/i) ||
    navigator.userAgent.match(/iPad/i) ||
    navigator.userAgent.match(/iPod/i) ||
    navigator.userAgent.match(/BlackBerry/i) ||
    navigator.userAgent.match(/Windows Phone/i)
  ) {
    return true;
  } else {
    return false;
  }
}

Related questions

0 votes
asked Oct 1, 2023 in JavaScript by GeorgeBell
+1 vote
asked Dec 4, 2019 in JavaScript by SakshiSharma
...