-1

Just a general question. I'm developing a website that is going to be used on a variety of different devices.

Is it possible to check which device the website is running on. IOS, Android, Desktop etc. with Javascript or Angular? OBS NOT JQUERY

Sorry don't know what to google, can you point me in the right direction?

Thank you

Adam Konieska
  • 2,738
  • 3
  • 12
  • 27
andrea
  • 93
  • 3
  • 14
  • 3
    Here is the answer how to detect browser device type: http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery – Dhaval Soni Jun 07 '16 at 13:28

2 Answers2

1

What is the best way to detect a mobile device in jQuery?

Here it is asked the same question. You can use JQuery for this.

EDIT:

Try this.

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};
Community
  • 1
  • 1
  • Thank you, I'm using angular JS to build my application so i'd rather not use JQuery. Is there a way to do it without using JQuery? – andrea Jun 07 '16 at 13:31
1

What is the best way to detect a mobile device in jQuery?

Use this for detect device using javascript only :

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 // some code..
}
Community
  • 1
  • 1
Dhaval Soni
  • 195
  • 1
  • 12
  • you basically copied the answer from a duplicate question [link](http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery), you should refer to the original answer... like @[Dhaval Soni](http://stackoverflow.com/users/4829473/dhaval-soni) did – Tom Shen Jun 07 '16 at 13:42