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

前端 未结 9 1100
时光说笑
时光说笑 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:39

    Firstly, you can get IE9 preview by downloading it from Microsoft's site: http://ie.microsoft.com/testdrive/

    Secondly, parseInt($.browser.version) > 9 would presumably check that the version is greater than 9, which of course it won't be until v10 is released. (you maybe intended >= ('greater than or equal to')?

    I usually tell people to avoid browser detection or browser-specific code. There are times when it is necessary, but they're quite rare. Most of the time the developer would be better served by knowing what was failing and working around it (tools like Modernizr really help for this sort of thing).

    However there are times when one simply has to do browser detection.

    In your case, if you really need to detect IE, don't do it the way you're doing (ie checking for version 9); it'd be better to check for older versions, and I'd suggest that a conditional comment would be the best way to do it.

    
    

    Then your if() statement later on can just look like this:

    if(i_am_old_ie) {
       //do stuff for IE6/7/8
    } else {
       //do stuff for all other browsers (including IE9)
    }
    

提交回复
热议问题