How can I determine which version of IE a user is running in JavaScript?

后端 未结 12 1885
生来不讨喜
生来不讨喜 2021-02-04 04:48

In some existing code there is a test to see if the user is running IE, by checking if the object Browser.Engine.trident is defined and returns true.

But how can I deter

12条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 05:16

    This should give you more details than you'll want:

    var agent = navigator.userAgent;
    var msiePattern = /.*MSIE ((\d+).\d+).*/
    if( msiePattern.test( agent ) ) {
      var majorVersion = agent.replace(msiePattern,"$2");
      var fullVersion = agent.replace(msiePattern,"$1");
      var majorVersionInt = parseInt( majorVersion );
      var fullVersionFloat = parseFloat( fullVersion );
    }
    

提交回复
热议问题