0

How do i detect what browser does the client using?

i saw there is a $.browser in Jquery API Documention but its not longer works in jQuery 1.9.1.

any suggestions?

Boaz Hoch
  • 1,179
  • 1
  • 11
  • 36
  • *Why* do you want to know the browser ? Did you look at why they removed it ? What do you want more than `navigator.userAgent` ? – Denys Séguret Apr 09 '13 at 11:45
  • possible duplicate of [What's the replacement for $.browser](http://stackoverflow.com/questions/9645803/whats-the-replacement-for-browser) – Quentin Apr 09 '13 at 11:47

4 Answers4

1

You can use the jQuery Migrate plugin and call the $.browser. It will work!

Using the plugin is easy; just include it immediately after the script tag for jQuery, for example.

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.js"></script>

JS:

$.each($.browser, function(i, val) {
  $("<div>" + i + " : <span>" + val + "</span>")
  .appendTo( document.body );
});

DEMO HERE (See Migrate 1.1.0 check box is checked on left side)

palaѕн
  • 64,836
  • 15
  • 100
  • 121
1

$.browser has been removed in 1.9 as it's was suggested feature detection was preferred via $.support

Check http://api.jquery.com/jQuery.support/

Jaydeep Rajput
  • 3,359
  • 14
  • 35
1

See this http://jquery.com/upgrade-guide/1.9/#jquery-browser-removed

Use jQuery Migrate plugin as William suggested

Dhaval Marthak
  • 16,632
  • 6
  • 39
  • 66
1

I will suggest you to use feature detection instead of browser detection. Here is some detail about feature detection:

http://api.jquery.com/jQuery.support/

But for answer to your question, you can use this code to detect browser:

<script type="text/javascript">
 $(document).ready(function() {
    if (!navigator.userAgent.match(/mozilla/i) && 
        ! navigator.userAgent.match(/webkit/i) ){
        alert('Mozilla');
    }
 });
</script>
Sanjeev Rai
  • 6,019
  • 4
  • 20
  • 33