Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect device type using javascript [closed]

I am developing an web application where I need to detect the device from javascript. Could anybody tell me whats the best way to do it ? I found several solution by googling. But no one is full proof. I do not want to use server side detection like WURFL.

My update

I am detecing device by matching CSS media queries using javascript. For media query matching using polyfill by Paul Irish https://github.com/paulirish/matchMedia.js/

like image 735
MAK Ripon Avatar asked Sep 04 '25 17:09

MAK Ripon


1 Answers

You can use:

  1. JS: Detect by user agent

     if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))
    

    Take the user agent strings from here: http://www.useragentstring.com/pages/useragentstring.php.

  2. CSS: Use responsive design

  3. JS: Detect the screen width by screen.width