Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect whether browser is iOS, android or desktop using jquery?

The idea is to make a button that says "get app now" with a link that changes based on whether its an android phone iPhone or none. I looked through stackexchange for answers but nothing is clear for someone who has no js experience

like image 615
Tom Avatar asked Jan 26 '26 08:01

Tom


1 Answers

Try this,

Unknown is desktop or any other phone

function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

  if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
  {
    return 'iOS';

  }
  else if( userAgent.match( /Android/i ) )
  {

    return 'Android';
  }
  else
  {
    return 'unknown'; 
  }
}

Source: Detecting iOS / Android Operating system

like image 176
Eduardo Iglesias Avatar answered Jan 28 '26 21:01

Eduardo Iglesias