Java Reference
In-Depth Information
of this object, namely the alert() and prompt() methods. For simplicity, we previously referred to
these as functions, but they are, in fact, methods of the browser's window object.
Another object made available by the browser is the page itself, represented by the document object.
Again, you have already used methods and properties of this object. Recall from previous chapters
that you used the document object's write() method to write information to the page.
A variety of other objects exist, representative of the HTML you write in the page. For example,
there is an img object for each <img/> element that you use to insert an image into your document.
The collection of objects that the browser makes available to you for use with JavaScript is generally
called the browser object model (BOM).
Note You will often see this termed the document object model (DOM); it is
incorrect to do so. Throughout this topic, we'll use the term DOM to refer to
the W3C's standard document object model, which is discussed in the next
chapter.
All this added functionality of JavaScript comes with a potential downside: There is no standard
BOM implementation (although some attempt is being made with the HTML5 specification). Which
collections of objects are made available to you is highly dependent on the brand and version of the
browser that you are using. Some objects are made available in some browsers and not in others,
whereas other objects have different properties and methods in different browsers. The good news is
that browser makers typically do not change much of their browser's BOM, because doing so would
create a rift in interoperability. This means if you stick to the core functionality of the BOM (the
common objects in all browsers), your code is more likely to work between the different browsers
and versions. This chapter's focus is the BOM core functionality. You can achieve a lot in JavaScript
by just sticking to the core.
introduCtion to the BroWser's oBjeCts
This section introduces the objects of the BOM that are common to all browsers.
In Chapter 5, you saw that JavaScript has a number of native objects that you can access and use.
Most of the objects are those that you need to create yourself, such as the String and Date objects.
Others, such as the Math object, exist without you needing to create them and are ready for use
immediately when the page starts loading.
When JavaScript is running in a web page, it has access to a large number of other objects made
available by the web browser. Like the Math object, these are created for you rather than your
needing to create them explicitly. As mentioned, the objects, their methods, properties, and events
are all mapped out in the BOM.
The BOM is very large and potentially overwhelming at first. However, you'll find that initially you
won't be using more than 10 percent of the available objects, methods, and properties in the BOM. You
 
Search WWH ::




Custom Search