Code Monkey home page Code Monkey logo

uautils's Introduction

=======

uautils is a simple JavaScript utilities for analysing User Agent string.

Usage

uautils is an Object has static methods such as getBrowser() and getOS(). Call these methods to assign a value to an Object.

var obj = uautils.getBrowser();

getBrowser() can reffer browser informations.

//Example UA: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
var obj = uautils.getBrowser();
console.log(obj.name);  //"Chrome"
console.log(obj.version); //23.0127197
console.log(obj.versionString); //"23.0.1271.97"
console.log(obj.vendor);  //"Google Inc."
console.log(obj.engine);  //"WebKit"
console.log(obj.engineVerString); //"537.11"
console.log(obj.engineVer); //"537.11"

getOS() can reffer OS informations.

//Example UA: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
var obj = uautils.getOS();
console.log(obj.name);  //"Windows 7"
console.log(obj.version); //6.1

You can set custom UA string attribute.

//Example UA: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
var targetOS = uautils.getOS("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
var currentOS = uautils.getOS(); //without an attribute, reffer to window.userAgent

obj.version is a Number so that you can compare.

var isNewerThanXP = (targetOS.version > currentOS.version) ? true : false; //true

Acknowledgements

Copyright © 2012 Katsumasa Tamanaha (kTmnh). Released under the MIT License.

uautils's People

Contributors

ktmnh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.