1

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.

4

2 回答 2

2

我将外壳更改为“Android”,它似乎工作正常:http: //jsfiddle.net/fjr5g/4/

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

如果这仍然对您不起作用(尽管它应该),您可以使用字符串navigator.userAgent.toLowerCase()并匹配"android".

于 2013-07-30T15:23:07.073 回答
0

我写了一个小型库,它将返回您需要了解的有关浏览器类型的所有数据https://github.com/dj10dj100/what_browser。在里面你可以打电话

if(what.device._android() == true){ 
// do code 
}
于 2014-08-27T19:31:36.760 回答