Detect IE version (prior to v9) in JavaScript

前端 未结 30 1428
半阙折子戏
半阙折子戏 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 09:03

    Your code can do the check, but as you thought, if someone try to access your page using IE v1 or > v19 will not get the error, so might be more safely do the check with Regex expression like this code below:

    var userAgent = navigator.userAgent.toLowerCase();
    // Test if the browser is IE and check the version number is lower than 9
    if (/msie/.test(userAgent) && 
        parseFloat((userAgent.match(/.*(?:rv|ie)[\/: ](.+?)([ \);]|$)/) || [])[1]) < 9) {
      // Navigate to error page
    }
    

提交回复
热议问题