Today, a project needs to determine the IE version number, and because JQuery 2.0 to remove the browser version number of the judge (it recommended feature detection), so I saw a foreigner wrote a piece of code:
| 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 piece of code is really clever! Both brief and backward compatible! The general practice is: regular search user_agent;
But because of historical reasons, User_agent has been inaccurate, and by the major manufacturers to change the mess.
Like what:
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
The above code is strongly recommended!
The one you wrote
| code is as follows |
copy code |
| <span id=" Css "></span> <script> if ( Navigator.userAgent.indexOf ("MSIE") >0) { //is an IE browser if (navigator.userAgent.indexOf ("MSIE 6.0") >0 { //6.0 uses 1. CSS css.innerhtml= ' <link href= ' 1.css ' rel= ' stylesheet ' type= ' text/css ' > ' } if ( Navigator.userAgent.indexOf ("MSIE 7.0") >0) { //7.0 uses 2. CSS css.innerhtml= ' <link href= "2.css" rel= "stylesheet" type= "text/css" > ' } }else { //otherwise use 3 . CSS and a specific browser you can use Navigator.useragent to obtain information specific use to see yourself css.innerhtml= ' <link href= 3.css "rel=" stylesheet "type=" Text/css ">" } </script> |
The following recommendation of a few words to determine IE browser code
| The code is as follows |
Copy Code |
<script type= ' Text/javascript ' > Notie =-[1,]; if (-[1,]) { Standard browser Code }else{ The Code of IE only } </script> |