Why is browser sniffing not a recommended practice?

前端 未结 7 1757
旧时难觅i
旧时难觅i 2020-12-01 16:26

You hear it all over the place: using javascript to sniff the user agent string to detect browser versions is a Very Bad Thing. The latest version of jQuery has now deprecat

相关标签:
7条回答
  • 2020-12-01 17:13

    Because just sniffing the user agent (which is what jquery does to populate the $.browser object) doesn't tell you the whole truth.

    The user agent string can be easily changed in many browsers, so if you for example disable some features that don't work in IE from everybody who seems to be using IE, you might accidentally disable those features from some future browsers or users who just, for some reason (like for example to get around limitations based on browser sniffing), pretend to be using IE.

    This might not seem too big of a problem, but it is still bad practice.

    And yes, I am a IE sniffer too. I use

    $.browser.msie && document.all
    

    just to be sure.

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