Home > Web Front-end > JS Tutorial > body text

Using javascript to determine the IE version number is simple, practical and backward compatible_javascript skills

WBOY
Release: 2016-05-16 17:22:51
Original
1074 people have browsed it

Today I need to determine the IE version number in a project, and because jQuery 2.0 removes the judgment of the browser version number (it recommends feature detection), I saw a piece of code written by a foreigner:

Copy code The code is as follows:

var _IE = (function(){
var v = 3, div = document.createElement ('div'), all = div.getElementsByTagName('i');
while (
div.innerHTML = '',
all[0]
);
return v > 4 ? v : false ;
}()) ;

This code is really clever! Both brief and backward compatible! The general approach is: regular search for USER_AGENT;
However, due to historical reasons, USER_AGENT has always been inaccurate and has been changed in a mess by major manufacturers.

For example:
Copy code The code is as follows:

IE10: 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; rv 11.0) like Gecko

These What kind of messy strings are they? . . Who knows what IE12 will become! ! !
So using feature detection or USER-AGENT detection is neither reliable nor backwards compatible!

Highly recommend the above code!
————————————————————————-
When I first learned programming, I felt that I knew a lot and had a lot to write about;
But after really learning a lot of knowledge in depth, I painfully discovered that I knew too little! I want to write something, but it’s hard to do it.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template