Before lazy to write to judge ie version JS, because the Internet on this aspect of the code is too much, so copied from the Internet, put on the project only to find due to the timeliness of the problem, the code does not take effect. Just write one yourself. How to see the browser's kernel and other information----JS's Global object window navigator.useragent, this attribute is the information that contains the browser information, including the browser kernel we need Navigator.useragent This value is a string, you can use string IndexOf method or a regular match to verify the key string Ie11 and edge of the way to determine the difference, I will give a few graphs of this is IE11 useragent This is the edge of the useragent IE9 useragent IE8 useragent ie10
You must have found, ie11 and edge of the useragent is and ie8,9,10 difference is quite large, then use in writing JS need special judgment, the following gives me a good section of the judge is IE and give the IE version number of JS code section
function ieversion () {var useragent = navigator.useragent;//Get browser's useragent string var IsI E = Useragent.indexof ("compatible") >-1 && useragent.indexof ("MSIE") >-1; Determine if ie<11 browser var Isedge = useragent.indexof ("Edge") >-1 &&!isie; Determine if IE's Edge browser var isIE11 = useragent.indexof (' Trident ') >-1 && useragent.indexof ("rv:11.0") & Gt
-1;
if (Isie) {var reie = new RegExp ("MSIE (\\d+\\.\\d+);");
Reie.test (useragent);
var fieversion = parsefloat (regexp["$");
if (fieversion = = 7) {return 7;
else if (fieversion = = 8) {return 8;
else if (fieversion = = 9) {return 9;
else if (fieversion = =) {return 10; else {return 6;//ie version <=7}
else if (Isedge) {return ' Edge ';//edge} else if (isIE11) {R Eturn 11; IE11}else{return-1;//is not ie browser}}
The return value can be obtained by calling Ieversion (), with the following values
Value |
Value type |
Value Description |
-1 |
Number |
Not IE browser |
6 |
Number |
IE version <=6 |
7 |
Number |
Ie7 |
8 |
Number |
Ie8 |
9 |
Number |
Ie9 |
10 |
Number |
Ie10 |
11 |
Number |
Ie11 |
' Edge ' |
String |
IE's Edge browser |