How to detect device and operating system using mobile-detect.js plugin

Here I am going to introduce mobile-detect.js, A cool library written in javascript to detect which type of device is using by visitor so that you can display different output for different device holder or operating system holder. By using you can easily and quickly get device types like phone, tablet, desktop, mobile grade, os, versions etc.



This library will detect the device by comparing patterns against a given User-Agent string. You can find out information about the device rendering your web page and take action as per device output.

You can easily judge user device is mobile or not, if mobile, whether phone or tablet, which operating system visitor using and which version is (e.g. WebKit);

Here is the quick configuration.
First of all download mobile-detect.js library from Here

After that add mobile-detect.js on page and call MobileDetect object and pass user agent as parameter see following code.

<script src="mobile-detect.js"></script>
<script>
var md = new MobileDetect(window.navigator.userAgent);
console.log( md.mobile() );          // 'Sony'
console.log( md.phone() );           // 'Sony'
console.log( md.tablet() );          // null
console.log( md.userAgent() );       // 'Safari'
console.log( md.os() );              // 'AndroidOS'
console.log( md.is('iPhone') );      // false
console.log( md.is('bot') );         // false
console.log( md.version('Webkit') );         // 534.3
console.log( md.versionStr('Build') );       // '4.1.A.0.562'
console.log( md.match('playstation|xbox') ); // false
</script>




See official page for more details.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.