Skip to content

Instantly share code, notes, and snippets.

@alegut
Created July 12, 2018 06:57
Show Gist options
  • Select an option

  • Save alegut/ddd2a353dcc2f569379226bcdbc69e04 to your computer and use it in GitHub Desktop.

Select an option

Save alegut/ddd2a353dcc2f569379226bcdbc69e04 to your computer and use it in GitHub Desktop.
How to detect mobile userAgent in js
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment