Java Reference
In-Depth Information
Differences Between the DOM and the BOM
As mentioned earlier, there are two main differences between the Document Object Model and the
Browser Object Model. However, complicating the issue is the fact that a BOM is sometimes referred to
under the name DOM. Look out for this in any literature on the subject.
First, the DOM covers only the document of the web page, whereas the BOM offers scripting access
to all areas of the browsers, from the buttons to the title bar, including some parts of the page.
Second, the BOM is unique to a particular browser. This makes sense if you think about it: You
can't expect to standardize browsers, because they have to offer competitive features. Therefore,
you need a different set of properties and methods and even objects to be able to manipulate
them with JavaScript.
Representing the HTML Document as a Tree Structure
Because HTML is standardized so that web pages can contain only the standard features supported in
the language, such as forms, tables, images, and the like, a common method of accessing these features is
needed. This is where the DOM comes in. It provides a uniform representation of the HTML document,
and it does this by representing the entire HTML document/web page as a tree structure .
In fact, it is possible to represent any HTML document (or any XML document for that matter) as a tree
structure. The only precondition is that the HTML document should be well formed. Different browsers
might be tolerant, to a greater or lesser extent, of quirks such as unclosed tags, or HTML form controls
not being enclosed within a <form/> element; however, for the structure of the HTML document to be
accurately depicted, you need to be able to always predict the structure of the document. Abuses of the
structure, such as unclosed tags, stop you from depicting the structure as a true hierarchy, and there-
fore cannot be allowed. The ability to access elements via the DOM depends on the ability to represent
the page as a hierarchy.
What Is a Tree Structure?
If you're not familiar with the concept of trees, don't worry. They're just a diagrammatic means of repre-
senting a hierarchical structure.
Let's consider the example of a book with several chapters. If instructed to, you could fi nd the third
line on page 543 after a little searching. If an updated edition of the topic were printed with extra
chapters, more likely than not you'd fail to fi nd the same text if you followed those same instructions.
However, if the instructions were changed to, say, “Find the chapter on still-life painting, the section on
using watercolors, and the paragraph on positioning light sources,” you'd be able to fi nd that even in
a reprinted edition with extra pages and chapters, albeit with perhaps a little more effort than the fi rst
request required.
Books aren't particularly dynamic examples, but given something like a web page, where the informa-
tion could be changed daily, or even hourly, can you see why it would be of more use to give the second
set of directions than the fi rst? The same principle applies with the DOM. Navigating the DOM in a
hierarchical fashion, rather than in a strictly linear way, makes much more sense. When you treat the
DOM as a tree, it becomes easy to navigate the page in this fashion. Consider how you locate fi les on
Windows using Windows Explorer, which creates a tree view of folders through which you can drill
down. Instead of looking for a fi le alphabetically, you locate it by going into a particular folder.
Search WWH ::




Custom Search