How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

前端 未结 25 2628
谎友^
谎友^ 2020-11-22 06:19

How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

I tried this, but

25条回答
  •  终归单人心
    2020-11-22 06:45

    Here is how I do custom CSS for Internet Explorer:

    In my JavaScript file:

    function isIE () {
          var myNav = navigator.userAgent.toLowerCase();
          return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
    }
    
    jQuery(document).ready(function(){
        if(var_isIE){
                if(var_isIE == 10){
                    jQuery("html").addClass("ie10");
                }
                if(var_isIE == 8){
                    jQuery("html").addClass("ie8");
                    // you can also call here some function to disable things that 
                    //are not supported in IE, or override browser default styles.
                }
            }
        });
    

    And then in my CSS file, y define each different style:

    .ie10 .some-class span{
        .......
    }
    .ie8 .some-class span{
        .......
    }
    

提交回复
热议问题