Detect IE version (prior to v9) in JavaScript

前端 未结 30 1413
半阙折子戏
半阙折子戏 2020-11-22 08:44

I want to bounce users of our web site to an error page if they\'re using a version of Internet Explorer prior to v9. It\'s just not worth our time and money to

30条回答
  •  隐瞒了意图╮
    2020-11-22 08:59

    This function will return the IE major version number as an integer, or undefined if the browser isn't Internet Explorer. This, like all user agent solutions, is suceptible to user agent spoofing (which has been an official feature of IE since version 8).

    function getIEVersion() {
        var match = navigator.userAgent.match(/(?:MSIE |Trident\/.*; rv:)(\d+)/);
        return match ? parseInt(match[1]) : undefined;
    }
    

提交回复
热议问题