What is the correct way to detect Opera using jQuery?

前端 未结 9 1700
梦毁少年i
梦毁少年i 2021-02-19 04:52

Amazon.com recently updated their javascript, and it\'s causing problems with some Opera browsers.

Their browser detection code looks like so, but it\'s faulty:

9条回答
  •  -上瘾入骨i
    2021-02-19 05:49

    Prior to jQuery 1.3, you could use jQuery.browser:

    if( $.browser.opera ){
      alert( "You're using Opera version "+$.browser.version+"!" );
    }
    

    From version 1.3, you should use jQuery.support instead.

    Main reason for this is that should should avoid checking for browsers, as features may change from version to version, making your code obsolete in no time.

    You should always try to use feature detection instead. This will allow you to see if current browser supports the feature you're trying to use, regardless the browser brand, version, etc.

提交回复
热议问题