How can you detect the version of a browser?

后端 未结 28 1903
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:35

I\'ve been searching around for code that would let me detect if the user visiting the website has Firefox 3 or 4. All I have found is code to detect the type of browser but

28条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 00:12

    jQuery can handle this quite nice (jQuery.browser)

    var ua = $.browser;
    if ( ua.mozilla && ua.version.slice(0,3) == "1.9" ) {
        alert( "Do stuff for firefox 3" );
    }
    

    EDIT: As Joshua wrote in his comment below, jQuery.browser property is no longer supported in jQuery since version 1.9 (read jQuery 1.9 release notes for more details). jQuery development team recommends using more complete approach like adapting UI with Modernizr library.

提交回复
热议问题