JavaScript Tutorials - Herong's Tutorial Examples - Version 2.21, by Dr. Herong Yang
DOM Level Test - document.implementation.hasFeature
This section provides a tutorial example of using the document.implementation.hasFeature() method to test DOM levels supported in a particular Web browser.
In DOM Level 1, 2, and 3 specifications, there is one method that will level you to test what levels of DOM specifications are supported in a specific Web browser: document.implementation.hasFeature(feature, level). It returns true, if the specified feature and level is supported by the Web browser. Note that the level must be specified in the dot format like 1.0, 2.0, or 3.0.
I used this method in the tutorial example to test what levels of DOM are supported by Web browsers on my machine.
<html>
<!-- DOM_Level_Test.html
Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
-->
<head>
<title>DOM Level Test</title>
</head>
<body><pre>
<script type="text/javascript">
document.writeln("\nDOM Level 0 Test:");
document.writeln(" document.bgColor = "+document.bgColor);
for (var i=1; i<4; i++) {
document.writeln("\nDOM Level "+i+".0 Test:");
document.writeln(" Core "+i+".0 = "
+ document.implementation.hasFeature("Core", i+".0"));
document.writeln(" HTML "+i+".0 = "
+ document.implementation.hasFeature("HTML", i+".0"));
}
</script>
</pre></body>
</html>
When I use this script to test Internet Explorer 6.0, the result shows that DOM Core Level 1 is not supported. But DOM HTML Level 1 is supported, very strange.
DOM Level 0 Test: document.bgColor = #ffffff DOM Level 1.0 Test: Core 1.0 = false HTML 1.0 = true DOM Level 2.0 Test: Core 2.0 = false HTML 2.0 = false DOM Level 3.0 Test: Core 3.0 = false HTML 3.0 = false
When I use this script to test Mozilla Firefox 2.0, the result shows that DOM Core Level 1 and 2, and DOM HTML Level 2 are supported. But DOM HTML Level 1 is not supported.
DOM Level 0 Test: document.bgColor = #ffffff DOM Level 1.0 Test: Core 1.0 = false HTML 1.0 = true DOM Level 2.0 Test: Core 2.0 = true HTML 2.0 = true DOM Level 3.0 Test: Core 3.0 = false HTML 3.0 = false
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
Introduction to Built-in Object Types
►W3C's Document Object Model (DOM) Specifications
Overview of DOM Specifications
►DOM Level Test - document.implementation.hasFeature
Inheritance vs. Flattened Views of the API
A Web Document as A Tree of Different Interfaces
A Web Document as A Tree of Nodes
Dump Document in a New Window - JavaScript Source
Dump Document in a New Window - Firefox 2.0 Result