Get IE Browser Version Using JavaScript
The code below shows you the way to get the version of IE browser using JavaScript.
To do this, we simply look at User-Agent data (navigator.userAgent
) to determine whether the visitors are using IE browser and then extract IE version from it.
ie-browser.js
function getIEVersion() {
if (navigator && navigator.userAgent) {
var userAgent = navigator.userAgent;
// detect IE below 11
if (userAgent.indexOf('MSIE') !== -1) {
var parts = userAgent.split('MSIE');
var version = parseInt(parts[1]);
return version;
}
// detect IE 11
if (userAgent.indexOf('Trident/') !== -1) {
var parts = userAgent.split('rv:');
var version = parseInt(parts[1]);
return version;
}
}
// not found
return null;
}
Use the function:
// Mozilla/4.0 (compatible; MSIE 5.50; Windows 98; SiteKiosk 4.8)
console.log(getIEVersion()); // IE version: 5
// Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
console.log(getIEVersion()); // IE version: 6
// Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)
console.log(getIEVersion()); // IE version: 7
// Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)
console.log(getIEVersion()); // IE version: 8
// Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7)
console.log(getIEVersion()); // IE version: 9
// Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0
console.log(getIEVersion()); // IE version: 10
// Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
console.log(getIEVersion()); // IE version: 11