Detect Internet Explorer 6 or below in jQuery

前端 未结 13 2406
野的像风
野的像风 2020-12-12 17:44

I\'m new to jquery and was wondering: is a simple way to detect whether a browser is Internet Explorer 6 or below?

相关标签:
13条回答
  • 2020-12-12 18:29

    Also, another good point is that with JQuery, you are not supposed to worry about the version.

    That doesn't help if you're using jquery to fix an IE6 css rendering bug though.

    0 讨论(0)
  • 2020-12-12 18:30

    As simple as this:

    if($.browser.msie && $.browser.version=="6.0") alert("Im the annoying IE6");
    

    Update

    Please note that $.browser is removed from jQuery 1.9

    If you still need to use $.browser in jQuery 1.9 (or other deprecated functions), try jQuery-migrate (https://github.com/jquery/jquery-migrate/ - http://code.jquery.com/jquery-migrate-1.2.1.js)

    0 讨论(0)
  • 2020-12-12 18:33

    Just to let people know $.browser.msie && /6.0/.test(navigator.userAgent) is not reliable, I've come to this question looking for an answer to a problem with the JQuery bgiframe which breaks on my machine because I have 'Media Center PC 6.0' in my navigator.userAgent string. I've now edited the source to use the $browser.version test.

    Its silly of JQuery to deprecate these browser tests because ugly as they may be they are necessary to deal with the ugly state of the browser ecosystem.

    0 讨论(0)
  • 2020-12-12 18:35

    "While it is unlikely jQuery.browser will be removed, every effort to use jQuery.support and proper feature detection should be made."

    So I say go ahead and use it. They have to maintain backwards-compatibility with scripts that still use the user-agent sniffing method.

    0 讨论(0)
  • 2020-12-12 18:37
    if ($.browser.msie && parseInt($.browser.version, 10) <= 6) {
      alert("I'm not dead yet!"); 
    }
    

    -- update

    Please not that $.browser is removed from jQuery 1.9

    0 讨论(0)
  • 2020-12-12 18:39

    jQuery checks for features, rather than "browsers". That said, you can use the jQuery.support method to detect what the users browser is capable of.

    Deprecated Methods (Do not use)

    • $.browser
    • $.browser.version
    • $.boxModel

    https://api.jquery.com/jQuery.support will give you a summary of which features are supported by which browsers. Taking that data, you'll develop a couple conditional checks to determine if the browser being used is your target browser or not.

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