Detect IE version (prior to v9) in JavaScript

前端 未结 30 1985
半阙折子戏
半阙折子戏 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:04

    This is my preferred way of doing it. It gives maximum control. (Note: Conditional statements are only supported in IE5 - 9.)

    First set up your ie classes correctly

    
    
    
    
          
    
    

    Then you can just use CSS to make style exceptions, or, if you require, you can add some simple JavaScript:

    (function ($) {
        "use strict";
    
        // Detecting IE
        var oldIE;
        if ($('html').is('.lt-ie7, .lt-ie8, .lt-ie9')) {
            oldIE = true;
        }
    
        if (oldIE) {
            // Here's your JS for IE..
        } else {
            // ..And here's the full-fat code for everyone else
        }
    
    }(jQuery));
    

    Thanks to Paul Irish.

提交回复
热议问题