tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

jQuery.browser

jQuery.browser

Returns: Map

Description: We recommend against using this property, please try to use feature detection instead (see jQuery.support). Contains flags for the useragent, read from navigator.userAgent. While jQuery.browser will not be removed from future versions of jQuery, every effort to use jQuery.support and proper feature detection should be made.

jQuery.browser

version added: 1.0
Deprecated in jQuery 1.3 (see jQuery.support) Contains flags for the useragent, read from navigator.userAgent. While it is unlikely jQuery.browser will be removed, every effort to use jQuery.support and proper feature detection should be made.
Available flags are:
  • safari
  • opera
  • msie
  • mozilla

This property is available before the DOM is ready, therefore you can use it to add ready events only for certain browsers.

There are situations where object detection is not reliable enough, in such cases it makes sense to use browser detection.

A combination of browser and object detection yields quite reliable results.

Examples

Example 1

Show the browser info.
    jQuery.each(jQuery.browser, function(i, val) {
      $("<div>" + i + " : <span>" + val + "</span>")
                .appendTo(document.body);
    });
The output of the code above will be:
Full source:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>

  <script type="text/javascript" language="javascript">
  $(document).ready(function(){
    jQuery.each(jQuery.browser, function(i, val) {
      $("<div>" + i + " : <span>" + val + "</span>")
                .appendTo(document.body);
    });
  });
  </script>
  <style>
  p { color:green; font-weight:bolder; margin:3px 0 0 10px; }
  div { color:blue; margin-left:20px; font-size:14px; }
  span { color:red; }
  </style>
</head>
<body>
  <p>Browser info:</p>
</body>
</html>

Example 2

Returns true if the current useragent is some version of Microsoft's Internet Explorer.
$.browser.msie

Example 3

Alerts "this is safari!" only for safari browsers
if ($.browser.safari) {
   alert("this is safari!");
}

Example 4

Alerts "Do stuff for firefox 3" only for firefox 3 browsers.
jQuery.each(jQuery.browser, function(i, val) {
  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
     alert("Do stuff for firefox 3")
});

Example 5

Set a CSS property to specific browser.
jQuery.each(jQuery.browser, function(i) {
  if($.browser.msie){
     $("#div ul li").css("display","inline");
  }else{
     $("#div ul li").css("display","inline-table");
  }
});

jQuery.browser.version

Returns: String

Description: The version number of the rendering engine for the user's browser.

jQuery.browser.version

version added: 1.1.3

Here are some typical results:

  • Internet Explorer: 6.0, 7.0
  • Mozilla/Firefox/Flock/Camino: 1.7.12, 1.8.1.3, 1.9
  • Opera: 9.20
  • Safari/Webkit: 312.8, 418.9

Note that IE8 claims to be 7 in Compatibility View.

Examples

Example 1

Returns the browser version.
$("p").html("The browser version is: <span>" +
                jQuery.browser.version + "</span>");
The output of the code above will be:

Example 1 - Full source:

<!DOCTYPE html>
<html>
<head>
  <style>
  p { color:blue; margin:20px; }
  span { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>  
  <script type="text/javascript" language="javascript">
     $(document).ready(function(){
$("p").html("The browser version is: <span>" +
                jQuery.browser.version + "</span>");
     });
  </script>
</head>
<body>
<p>
</p>
</body>
</html>

Example 2

Alerts the version of IE that is being used
if ( $.browser.msie ) {
  alert( $.browser.version );
}

Example 3

Often you only care about the "major number," the whole number. This can be accomplished with JavaScript's built-in parseInt() function:
if (jQuery.browser.msie) {
  alert(parseInt(jQuery.browser.version));
}
Was this information helpful?
   

Comments