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

后端 未结 12 1879
生来不讨喜
生来不讨喜 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:08

    If you are checking for a certain functionality, you should check for it directly, e.g. if (window.focus) {window.focus();} Browser detection is never reliable enough.

    For more details on object vs browser detection, check out this article at Quirksmode.

    On the other hand, if the feature you need IS the browser type and version, e.g. for statistical purposes, go with navigator.appName and navigator.appVersion. (Beware though - many less popular browsers masquerade themselves as MSIE 6 or 7, as certain sites block anything that's not IE on the premise that "all the modern browsers are IE, right?" (hint: not anymore).)

提交回复
热议问题