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

后端 未结 12 1887
生来不讨喜
生来不讨喜 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条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 05:07

    This is the script I use and it seems to work well enough:

    // Returns 0 if the browser is anything but IE
    function getIEVersion() {
       var ua = window.navigator.userAgent;
       var ie = ua.indexOf("MSIE ");
       return ((ie > 0) ? parseInt(ua.substring(ie+5, ua.indexOf(".", ie))) : 0);
    }
    

    Hope that helps someone...

提交回复
热议问题