General judge whether the version number is between the two, can also be matched to determine whether more than a certain version number, less than the reverse can be
PS: Make sure the version specification is consistent, for example, the N-bit version number of the. Number split
var APP = {};
Determine whether the specified version is in the version range, and make sure that the version specification is consistent; for example (.,..,..)
App.betweenversion = function (curr,start,end,separator) {if Curr = Start | | | curr = = END} {return true; } var separator = Separator | |
'.';
var Curr = curr.split (separator);
var start = start.split (separator);
var end = End.split (separator);
var gtstart = false;
var ltend = false;
Gtstart = App.gttargetversion (App.compareversionele (Curr,start));
if (!gtstart) {return false; } return!
App.gttargetversion (App.compareversionele (curr,end));
};
App.compareversionele = function (curr,target) {var len = curr.length;
var temp = [];
var left,right;
for (Var i=;i<len;i++) {left = +curr[i];
right = +target[i];
if (left = right) {Temp.push ();
}else if (Left > right) {temp.push ();
}else{Temp.push (-);
} return temp;
}; App.gttargetvErsion = function (arr) {var res = true;
var Curr,next;
for (Var i=,len=arr.length;i<len;i++) {Curr = Arr[i];
Next = arr[i+];
if (Curr>next) {if (Curr = =) {res = false;
Break
} if (Curr = =) {res = true;
Break
}}else if (Curr = = next) {if (Curr = =-) {res = false;
Break
} if (Curr = =) {res = true;
Break
}}else{if (Curr = =-) {res = false;
Break
} if (Curr = =) {res = true;
Break
}}//Console.log (RES);
return res;
var res = app.betweenversion (' ... ', ' ... ', ' ... ', ' ... '); Console.log (RES);
The current project has to determine whether the specified version of the two version of this demand, Baidu Google found a lap, the code is limited, not universal, or even a bunch of wrong things around ...
The current method has two main points, one is the need to convert the cut version number to a numeric array, and a comparison of the size of the time to 1 0 13 values, so that regardless of the number of separate version number, the overall divided into several paragraphs, can be correctly compared.
Here's how to share the code for JavaScript detection browser types and versions
Object/Feature Detection method
This method is a common method for judging browser capabilities rather than the exact model of browsers. Most JS experts think this method is the most appropriate, because they think the script written by this method will stand the test of the future.
Get IE Browser version number
//return value, show IE's major version number
function Getiever () {
var ua = navigator.useragent;//Get client information
var B = Ua.indexof ("MSIE"); Detects the position of the special string "MSIE"
if (b < 0) {return
0;
}
Return parsefloat (ua.substring (b + 5, Ua.indexof (";", b))); Intercepts the version number string and converts to numeric
}
alert (Getiever ());//return value 8 (my IE8)
You can use this approach if you are more concerned about the capabilities of your browser than the actual identity.
User-agent String Detection method
The User-agent string provides a large amount of information about a Web browser, including the name and version of the browser.
var ua = Navigator.userAgent.toLowerCase (); Get client info
var info = {
ie:/msie/.test (UA) &&!/opera/.test (UA), //matching IE browser
op:/opera/.test ( UA), ///Match Opera browser
SA:/version.*safari/.test (UA), ///Match Safari browser
Ch:/chrome/.test (UA), // Matching Chrome browser
FF:/gecko/.test (UA) &&!/webkit/.test (UA) //matching Firefox browser
};
(info.ie) && alert ("IE browser");
(INFO.OP) && alert ("Opera browser");
(INFO.SA) && alert ("Safari browser");
(INFO.FF) && alert ("Firefox browser");
(info.ch) && alert ("Chrome browser");
Usually the most we do is to determine whether IE, the other browsers will generally meet the standard. Some customers are satisfied with IE and FF only. Then we can do this:
var Isie = (Navigator.appname = = "Microsoft Internet Explorer");
To judge ie far more than one method, you can use IE more specific things, such as window. Activexobject,document.all and so on, these are the object/feature detection Method! Usually you have to write different styles in different browsers (because IE style parsing is different), you have to judge the version. You can do this.
Get IE Browser version number
//return value, show IE's major version number
function Getiever () {
var ua = navigator.useragent;//Get client information
var B = Ua.indexof ("MSIE"); Detects the position of the special string "MSIE"
if (b < 0) {return
0;
}
Return parsefloat (ua.substring (b + 5, Ua.indexof (";", b))); Intercepts the version number string and converts to numeric
}
alert (Getiever ());//return value 7
Detection operating system:
var Iswin = (navigator.userAgent.indexOf ("Win")!=-1); If it is a Windows system, returns True
var Ismac = (navigator.userAgent.indexOf ("Mac")!=-1); If it is a Macintosh system, returns True
var Isunix = (navigator.userAgent.indexOf ("X11")!=-1); If it is a UNIX system, returns true
var islinux = (navigator.userAgent.indexOf ("Linux")!=-1); Returns true if it is a Linux system