ドキュメント

Utilities/jQuery.support

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Utilities

jQuery.support

Added in jQuery 1.3 A collection of properties that represent the presence of different browser features or bugs.

jQuery comes with a number of properties included, you should feel free to add your own. Many of these properties are rather low-level so it's doubtful that they'll be useful in general day-to-day development, but mostly used by plugin and core developers.

The values of all the support properties are determined using feature detection (and do not use any form of browser sniffing). There are some excellent resources that explain how feature detection works:

The tests included in jQuery.support are as follows:

  • boxModel: Is equal to true if the page and browser are rendering according to the W3C CSS Box Model (is currently false in IE 6 and 7 when they are in Quirks Mode). This property is null until document ready occurs.
  • cssFloat: Is equal to true if style.cssFloat is used to access the current CSS float value (is currently false in IE, it uses styleFloat instead).
  • hrefNormalized: Is equal to true if the browser leaves intact the results from getAttribute("href")(is currently false in IE, the URLs are normalized).
  • htmlSerialize: Is equal to true if the browser properly serializes link elements when innerHTML is used (is currently false in IE).
  • leadingWhitespace: Is equal to true if the browser preserves leading whitespace when innerHTML is used (is currently false in IE 6-8).
  • noCloneEvent: Is equal to true if the browser does not clone event handlers when elements are cloned (is currently false in IE).
  • objectAll: Is equal to true if doing getElementsByTagName("*") on an object element returns all descendant elements (is currently false in IE 6, IE 7 and IE 8).
  • opacity: Is equal to true if a browser can properly interpret the opacity style property (is currently false in IE, it uses alpha filters instead).
  • scriptEval: Is equal to true if using appendChild/createTextNode to inject inline scripts executes them (is currently false in IE, it uses .text to insert executable scripts).
  • style: Is equal to true if getAttribute("style") is able to return the inline style specified by an element (is currently false in IE - it uses cssText instead).
  • tbody: Is equal to true if the browser allows table elements without tbody elements (is currently false in IE, which automatically inserts tbody if it is not present in a string assigned to innerHTML).
Examples:

Returns the box model for the iframe.

    $("p").html("This frame uses the W3C box model: <span>" +
                jQuery.support.boxModel + "</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("This frame uses the W3C box model: <span>" +
                jQuery.support.boxModel + "</span>");

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

Returns false if the page is in QuirksMode in Internet Explorer

jQuery.support.boxModel

false

NameType