Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Use userAgent to detect mobile device

Can anyone help me with this.

I would like to detect device such as Iphone, BB, andriod and browser to apply their specific css to make it liquefied or adjust to their resolution.

Does andriod and Iphone have difference resolution issue or css problem when it comes to mobile browser because i plan to use same css for those 2 because i know they are using the same browser safari as default.

like image 452
Bert Avatar asked Feb 16 '12 06:02

Bert


1 Answers

Here is an example in javascript:

var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);

if(isMobile) {
   // User-Agent is IPhone, IPod, IPad, Android or BlackBerry
}

To check for a specific User-Agent string you can do:

if(navigator.userAgent.match(/iPhone/)) {
   // The User-Agent is iPhone
}
like image 58
Cyclonecode Avatar answered Oct 02 '22 13:10

Cyclonecode