Skip to content
Vijay Koushik, S edited this page Nov 10, 2018 · 2 revisions

device-capabilities.js

A JavaScript library that detects the client device's capabilities for support of several sensors like touch, motion and orientation sensors and also provides out of the box support for browser detection and OS/Platform detection.

Description

Device capabilites.js is a pure JavaScript library loosely based on the device module in Photonstrom's Phaser framework. The library is quick and simple to use. It can identify if the device is a desktop or mobile, detect the platform the device is running on and find out the name of the browser the library is running on.

Features

  • Browser detection
  • Platform detection
  • Device detection
  • Feature detection

Note: Other than "Feature detection" all other detections are based on the browser's User Agent String

Device Detection

Device capabilities.js library is able to detect and differentiate between Desktop and Mobile (Tablets are also detected as mobiles)

Browser Detection

The library can detect the name of the current browser.

Identifiable browsers are:

Desktop

  1. Chrome
  2. Firefox
  3. Internet Explorer
  4. Edge
  5. Opera
  6. Safari

Mobile Devices

  1. Chrome for Android and iOS.
  2. Firefox for mobile.
  3. IE Mobile.
  4. Edge Mobile.
  5. Android Native browser.
  6. Silk browser for Kindle.

Platform Detection

The library is also able to detect the platform or operating system on which device is running.

Detectable Platforms are:

  1. Windows
  2. Linux
  3. Mac OS
  4. Windows Phone
  5. Android
  6. iOS
  7. WebOS
  8. Kindle
  9. Blackberry
  10. Firefox OS

Feature Detection

The library has the ability to detect the following api features supported by the browser and the device.

  1. HTML5 Local storage API
  2. HTML5 Canvas API
  3. Touch sensor API
  4. Game pad API

Usage

First, Download the device-capabilites.js library and include it in the html file

<script src="path/to/device-capabilities.js"></script>

Then instantiate the deviceCapabilities class and use its properties for examining the device's capabilities.

Example:

/* create an instace of the deviceCapabilites class*/
var devAbility = new Device.deviceCapabilities();

// Find out if the device is a desktop
if(devAbility.desktop){
    console.log("The device is a desktop");
}

// Check if the browser is chrome on a mobile device
if(devAbility.Browser.chromeMobile){
    console.log("The browser is chrome for mobile");
}

// Know if device supports touch
if(devAbility.Sensors.touch){
    console.log("The device supports touch interface");
}
Clone this wiki locally