ドキュメント

Utilities/jQuery.browser.version

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Utilities

jQuery.browser.version

Deprecated in jQuery 1.3 (see jQuery.support) The version number of the rendering engine for the user's browser.
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:

Returns the browser version.

    $("p").html("The browser version is: <span>" +
                jQuery.browser.version + "</span>");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("p").html("The browser version is: <span>" +
                jQuery.browser.version + "</span>");

  });
  </script>
  <style>
  p { color:blue; margin:20px; }
  span { color:red; }
  </style>
</head>
<body>
  <p>
  </p>
</body>
</html>

Alerts the version of IE that is being used

if ( $.browser.msie )
 alert( $.browser.version );

}

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));
}

NameType