There are many ways to judge the version number of IE browser using js. I will introduce three related instances below. I recommend using the last concise version to judge IE browser. The most comprehensive method is the second.
In today's project, you need to determine the IE version number. Because jQuery 2.0 does not judge the browser version number (it recommends Feature Detection), you can see a piece of code written by a foreigner:
| The Code is as follows: |
Copy code |
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; }()); |
This code is really clever! Both introduction and backward compatibility! The general practice is: regular search USER_AGENT;
However, due to historical reasons, USER_AGENT has never been accurate and has been changed by major vendors.
For example:
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
We strongly recommend the above Code!
A self-written
| The Code is as follows: |
Copy code |
<Span id = "Css"> </span> <Script> If (navigator. userAgent. indexOf ("MSIE")> 0) { // Whether the browser is Internet Explorer If (navigator. userAgent. indexOf ("MSIE 6.0")> 0) { // 6.0 use 1.CSS Css. innerHTML = '<link href = "1.css" rel =" stylesheet "type =" text/css ">' } If (navigator. userAgent. indexOf ("MSIE 7.0")> 0) { // 7.0 use 2.CSS Css. innerHTML = '<link href = "2.css" rel =" stylesheet "type =" text/css ">' } } Else { // Otherwise, you can use 3.CSS and a specific browser. You can use navigator. userAgent to obtain information. Css. innerHTML = '<link href = "3.css" rel =" stylesheet "type =" text/css ">' } </Script>
|
The following is a few recommended statements to determine the IE browser code.
| The Code is as follows: |
Copy code |
<Script type = 'text/javascript '> Notie =-[1,]; If (-[1,]) { // Standard browser code } Else { // Ie only code } </Script> |