Detect the type of OS using Javascript and do something different by OS

advertisements

So I've looked around to try to find something suited to my situation, and whilst i've found lots of snippets that allow me to detect screen sizes, or a particular OS, solutions i've found are incomplete, or I cant figure out how to modify them so that they will work how I need them to.

My favorite solution is http://www.quirksmode.org/js/detect.html but there is no android or windows phone detector which I need. upon trying to add it myself, I cant seem to get it to return Android instead of linux if I use

BrowserDetect.OS

i added this in the dataOS: property before linux, usign navigator.userAgent and navigator.platform but had no success

{
    string: navigator.userAgent,
    substring: "android",
    identity: "android"
},

What am I doing wrong? Alternatively if you can offer up a better solution i'm all ears. Essentially what i want the page to do is detect what OS you are using and redirect you to a link specific to each operating system so,

if you are IOS go to link a, if you are android go to link b, if you are blackberry 10 go to link c if you are windows phone go to link c, all others go to link.

Help is much appreciated! I figure the best option is to set up cases but I cant get my head around the OS detection part.


I changed the casing to "Android", and it seemed to work fine: http://jsfiddle.net/fjr5g/4/

    {
           string: navigator.userAgent,
           subString: "Android",
           identity: "Android"
    },

If this still doesn't work for you (though it should), you can use the string navigator.userAgent.toLowerCase() and match against "android".