1

I want to use $.browser in my script, but it doesn't work as I want. For example, in Chrome it has properties safari and webkit set to true.

Why does this happen?

Here is a fiddle.

Don't Panic
  • 41,125
  • 10
  • 61
  • 80

2 Answers2

3

In this case it happened because your fiddle use jQuery 1.7.2 in this release you can find:

// Deprecated, use jQuery.browser.webkit instead
if ( jQuery.browser.webkit ) {
    jQuery.browser.safari = true;
}

Both browsers chrome and safari are based on webkit.

Solutions:

  1. You can update jQuery. Like in this fiddle.
  2. You can use advices from docs like:

    $.browser.chrome = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
    $.browser.safari = ( $.browser.safari && /chrome/.test(navigator.userAgent.toLowerCase()) ) ? false : true;
    

You can watch this in action here.

Mateusz Rogulski
  • 7,357
  • 7
  • 44
  • 62
1

Probably 'cause that's part of Chrome's user agent. See here: http://www.useragentstring.com/pages/Chrome/

What you probably need might be answered in this SO answer.

Community
  • 1
  • 1
Juri
  • 32,424
  • 20
  • 102
  • 136