JavaScript Library For Browser/OS/Device Detection – Detect.js

Category: Javascript | March 8, 2016
Author:JustClear
Views Total:1,437 views
Official Page:Go to website
Last Update:March 8, 2016
License:MIT

Preview:

JavaScript Library For Browser/OS/Device Detection – Detect.js

Description:

Detect.js is a small JavaScript library used to detect OS, browser kernel, device and user agent. AMD supported and also can be implemented as a Node.js module.

How to use it:

Add the Detect.js JavaScript library to your webpages.

<script src="src/detect.js"></script>

Create html elements to output the results.

<ul>
  <li>Detect Version: <span id="version"></span></li>
  <li>User Agent: <span id="ua"></span></li>
  <li>Kernel: <span id="kernel"></span></li>
  <li>OS: <span id="os"></span></li>
  <li>Device: <span id="device"></span></li>
</ul>

The JavaScript.

;(function(D, doc) {
  console.log(D.version);
  console.log(D.ua);
  console.log(D.kernel());
  console.log(D.os());
  console.log(D.type('detector'));
  console.log(D.type({}));
  console.log(D.type([]));
  console.log(D.device());
  function get(id) {
    return doc.getElementById(id);
  }
  var version = get('version');
  var ua = get('ua');
  var kernel = get('kernel');
  var os = get('os');
  var device = get('device');
  version.innerText = D.version;
  ua.innerText = D.ua;
  kernel.innerText = D.kernel();
  os.innerText = D.os();
  device.innerText = D.device();
})(detect, document);

You Might Be Interested In:


Leave a Reply