Js judge ie version number of the simple implementation code
- 2020-03-30 02:12:40
- OfStack
JQuery 2.0 removes the judgment of browser version number (it recommends feature detection), here is a native judgment method written by foreigners, this code is really clever! Both brief, backwards compatible! The general approach is: regular search USER_AGENT;
However, due to historical reasons, USER_AGENT has always been inaccurate, and has been changed in a mess by various manufacturers. :
Such as:
Consumer: Mozilla / 5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64. Trident / 6.0)
IE11: Mozilla/5.0 (Windows NT 6.3; Trident / 7.0; The rv 11.0) like Gecko
What the hell are these strings... Who knows what IE12 will become!!
So using feature detection, or user-agent detection, is neither reliable nor backward compatible!
The following code is highly recommended!
var _IE = (function () {
var v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : false;
} ());
alert(_IE);