Javascript Reference
Categories: implementation

javascript implementation hasFeature( )

@March 15, 2008, 1:22 a.m.
hasFeature( )Firefox/Netscape/NN 6 IE 5(Mac)/6(Win) Chrome/Safari/DOM 1  

hasFeature("feature", "version")

  

Returns a Boolean true if the browser application supports (i.e., conforms to the required specifications of) a stated W3C DOM module and version. The closely related isSupported( ) method performs the same test on an individual node, allowing you to verify feature support for the current node type. Parameter values for the two methods are identical.

 

It is up to the browser maker to validate that the DOM implemented in the browser conforms with each module before allowing the browser to return true for the module. That doesn't necessarily mean that the implementation is bug-free or consistent with other implementations. Caveat scriptor.

 

In theory, you could use this method to verify module support prior to accessing a property or invoking a method. The following script fragment from the head portion of a document dynamically links a different external style sheet file for "true" CSS2 support:

var cssFile;
if (document.implementation.hasFeature("CSS", "2.0")) {
    cssFile = "styles/corpStyle2.css";
} else {
    cssFile = "styles/corpStyle1.css";
}
document.write(<link rel='stylesheet' type='text/css' href='" + cssFile + "'>");"
 

More browsers support this browser-wide method than the element-specific method, which may help more developers deploy it sooner.

 
Parameters
 
  • As of W3C DOM Level 2, permissible case-sensitive module name strings are: Core, XML, HTML, Views, StyleSheets, CSS, CSS2, Events, UIEvents, MouseEvents, MutationEvents, HTMLEvents, Range, and Traversal.
  • String representation of the major and minor version of the DOM module cited in the first parameter. For the W3C DOM Level 2, the version is 2.0, even when the DOM module supports another W3C standard that has its own numbering system. Thus, the test for HTML DOM module support is for Version 2.0, even though HTML is at 4.x.
 
Returned Value

Boolean value: true | false.


Powered by Linode.