Client Browser & Platform Detection Plugin - jQuery Depend

Client Browser & Platform Detection Plugin - jQuery Depend
File Size: 38.1 KB
Views Total: 55
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Depend is a jQuery browser & platform detection plugin to detect client browser (type and version), OS, device type, and other util information using the user agent.

In addition, the plugin enables the developer to do some cool stuff if the browser and/or platform doesn't fit the minimal requirements you specify.

How to use it:

1. Load the minified version of the jQuery Depend plugin from the dist folder.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/dist/jquery.depend.min.js"></script>

2. Get the browser type. Possible properties:

  • original
  • version
  • opera
  • operamini
  • operamobile
  • msie
  • edge
  • firefox
  • chrome
  • browser
  • safari
  • silk
  • mercury
  • webkit
  • trident
  • khtml
  • gecko
  • presto
  • x86
  • x64
  • arm
  • ia64
  • unknown
// chrome
$.browser.original

3. Get the browser version. Possible properties:

  • original
  • major
  • minor
  • build
  • revision
// 83.0.4103.97
$.browser.version.original

// 83
$.browser.version.major

// 0
$.browser.version.minor

// 4103
$.browser.version.build

// 97
$.browser.version.revision

4. Get the OS & device type. Possible properties:

  • type
  • original
  • tablet
  • mobile
  • pc
  • ipad
  • iphone
  • ipod
  • android
  • windowsphone
  • windows
  • mac
  • linux
  • x86
  • x64
  • arm
  • ia64
  • unknown
// Windows
$.platform.original

5. Execute custom codes based on the Browser and Platform:

$.depend({
  on: ($.browser.is('msie') && $.browser.version.isOrLess(8)),
  exe: function () {
    return 'IE, and version is or less than 8.0.';
  }
}, {
  on: ($.browser.is('msie') && $.browser.version.isMoreThan(8)),
  exe: function () {
    return 'IE, and version is more than 8.0.';
  }
}, {
  exe: function () {
    return 'not IE.';
  }
});

6. All possible API methods.

// checks if is a certain browser & OS & device type
// returns true or false
$.browser.is(string);
$.platform.is(string);

// checks if the browser fits the minimal requirements
browser.version.isEqual( major, minor, build, revision );
browser.version.isOrLess( major, minor, build, revision );
browser.version.isLessThan( major, minor, build, revision );
browser.version.isOrMore( major, minor, build, revision );
browser.version.isMoreThan( major, minor, build, revision );

This awesome jQuery plugin is developed by garafu. For more Advanced Usages, please check the demo page or visit the official website.