if condition: if the browser is IE and IE browser version is older than 9

前端 未结 9 1102
时光说笑
时光说笑 2020-12-24 09:17

The if condition below I think it says - if the browser is IE and IE browser version is newer than 9, but I don\'t have IE 9 to test it so it is hard to know the correct out

相关标签:
9条回答
  • 2020-12-24 09:51

    I found cascading it works great for multibrowser detection. This code was used to change a fade to show/hide in ie 8 7 6.

    $(document).ready(function(){
        if(jQuery.browser.msie && jQuery.browser.version.substring(0, 1) == 8.0)
             { 
                 $(".glow").hide();
                $('#shop').hover(function() {
            $(".glow").show();
        }, function() {
            $(".glow").hide();
        });
             }
             else
             { if(jQuery.browser.msie && jQuery.browser.version.substring(0, 1) == 7.0)
             { 
                 $(".glow").hide();
                $('#shop').hover(function() {
            $(".glow").show();
        }, function() {
            $(".glow").hide();
        });
             }
             else
             {if(jQuery.browser.msie && jQuery.browser.version.substring(0, 1) == 6.0)
             { 
                 $(".glow").hide();
                $('#shop').hover(function() {
            $(".glow").show();
        }, function() {
            $(".glow").hide();
        });
             }
             else
             { $('#shop').hover(function() {
            $(".glow").stop(true).fadeTo("400ms", 1);
        }, function() {
            $(".glow").stop(true).fadeTo("400ms", 0.2);});
             }
             }
             }
           });
    
    0 讨论(0)
  • 2020-12-24 09:52

    There's an even easier method.

    Since this is a comment, it will be ignored by all other browsers except IE.

    var IE;
    //@cc_on IE = navigator.appVersion;
    

    Then just use this in you'r script to detect all IE versions.

    if (IE) {
    //This is IE.
    }
    else {
    //This is NOT IE.
    }
    

    Or match against any version like this:

    if (IE <= 6) {}, if (IE < 9) }, if (IE == 7) {} etc etc...
    

    Here's the source where i found these types of conditionals: http://www.javascriptkit.com/javatutors/conditionalcompile.shtml

    0 讨论(0)
  • 2020-12-24 09:53

    Your code looks fine, but you forgot to set the radix parameter in parseInt:

    if ($.browser.msie && parseInt($.browser.version, 10) > 9){
    
      // you need to wait a couple years to test if it works...
      alert("I'm IE10 or 11...");
    
    }
    

    This cannot cause any errors

    0 讨论(0)
提交回复
热议问题