Get browser version of IE using Javascript

Sauron picture Sauron · Dec 18, 2009 · Viewed 36.2k times · Source

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?

Answer

YOU picture YOU · Dec 18, 2009

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])