Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get browser version of IE using Javascript [duplicate]

I am using the following code to get the version of IE in a system.

    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = parseFloat(b_version);
    alert(version);

But the version always get is 4 in IE^ and IE7. How can I get the exact version?

like image 327
Sauron Avatar asked Dec 18 '09 05:12

Sauron


3 Answers

You got 4 because of navigator.appVersion strings starts with 4.0 like this.

4.0 (compatible; MSIE 6.0; Windows NT 5.0; ...)

If you do like this, you will get MSIE 6.0 for above case

alert(navigator.appVersion.match(/MSIE [\d.]+/))

If you only want 6.0 you could do like

alert(navigator.appVersion.match(/MSIE ([\d.]+)/)[1])
like image 192
YOU Avatar answered Oct 19 '22 15:10

YOU


It's generally not a good idea to use version detection — in fact, even browser detection isn't recommended! Instead, try object detection.

like image 4
Avi Flax Avatar answered Oct 19 '22 16:10

Avi Flax


The below function isIE returns IE version if IE is detected else returns FALSE

function isIE () {
  var myNav = navigator.userAgent.toLowerCase();
  return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
}

This is based on the answer here by weroro.

like image 2
Binod Kalathil Avatar answered Oct 19 '22 15:10

Binod Kalathil