Example
The code is as follows |
Copy Code |
MSIE = Int (/msie (d+)/.exec ((navigator.useragent). toLowerCase ()) | | []) [1]); /* IE 11 changed its useragent format, so to further judge * * if (isNaN (MSIE)) { MSIE = int (/trident/.*; rv: (d+)/.exec ((navigator.useragent). toUpperCase ()) | | []) [1]); } |
Example
Good idea, add a DIV element, and then use the while loop to determine whether the div tag using IE conditional annotation contains the I tag, and if it does, V will increase by 1 until the browser cannot read the I tag. The V value at this time if greater than 4 is the actual version number of IE, or V is less than IE5 IE browser or non IE browser, return false.
The code is as follows |
Copy Code |
var ieversion = (function () { var v = 3, div = document.createelement (' div '), all = Div.getelementsbytagname (' i '); while ( div.innerhtml = ' <!--[if GT IE ' + (++v) + ']><i></i><! [endif]--> ', ALL[0] ); Www.111cn.net Return v > 4? V:false; })(); |
Example jquery
When you want to use it, you can use $.BROWSER.MSIE6~10 to do the judgment processing. The other is to directly modify the JQuery.browser.version of the method:
The code is as follows |
Copy Code |
<script type= "Text/javascript" src= "/jquery.min.js" ></script> <script type= "Text/javascript" > $ (function () { var useragent = Window.navigator.userAgent.toLowerCase ();
$.browser.msie10 = $.browser.msie &&/msie 10.0/i.test (useragent); $.BROWSER.MSIE9 = $.browser.msie &&/msie 9.0/i.test (useragent); $.BROWSER.MSIE8 = $.browser.msie &&/msie 8.0/i.test (useragent); $.browser.msie7 = $.browser.msie &&/msie 7.0/i.test (useragent); $.browser.msie6 =!$.browser.msie8 &&!$.browser.msie7 && $.browser.msie &&/msie 6.0/i.test ( useragent); Www.111cn.net $ (". Info"). HTML ( """"""); }); </script>
<body> <div class= "Info" ></div> </body> |
Final summary
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
So we should take the standard as the main.