简体   繁体   中英

Detect full version internet explorer with javascript?

Is it possible to detect the full version of internet explorer.

navigator.appVersion

navigator.appVersion only gives the major version, for example 9.0 But it doesn't show 9.0.8112.1642...

不幸的是,您无权访问JavaScript中的IE内部版本号。

There is a solution for this below, however only works in 32bit version of Windows: http://www.pinlady.net/PluginDetect/IE/

var e, obj = document.createElement("div"), 
    verIEfull = null; // Full IE version [string/null]

try{ 
    obj.style.behavior = "url(#default#clientcaps)";

    verIEfull = obj.getComponentVersion("{89820200-ECBD-11CF-8B85-00AA005B4383}","componentid").replace(/,/g,".");
}catch(e){};

I'd do this:

var IEVersion = 0;
if( window.attachEvent && /MSIE ([\d\.]+)/.exec(navigator.appVersion) ){
    IEVersion = parseInt( RegExp.$1 );
}

It's compact and dodges spoofed UserAgent strings by checking the event model is actually IE first:

From the microsoft development website

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
 navigator.userAgent;

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)

One possibility is that compare .NET versions with IE minor versions, if we get somewhere that table on microsoft IE documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM