Java Reference
In-Depth Information
object model (BOM). This is essentially a map of a browser's objects. Using it, you can
navigate your way around each of the objects made available by the browser, together with
their properties, methods, and events.
The first of the main objects you looked at was the window object. This sits at the very top
of the BOM's hierarchy. The window object contains a number of important sub‐objects,
including the location object, the navigator object, the history object, the screen object,
and the document object.
The location object contains information about the current page's location, such as its
filename, the server hosting the page, and the protocol used. Each of these is a property of the
location object. Some properties are read‐only, but others, such as the href property, not
only enable you to find the location of the page, but can be changed so that you can navigate
the page to a new location.
The history object is a record of all the pages the user has visited since opening his or
her browser. Sometimes pages are not noted (for example, when the location object's
replace() method is used for navigation). You can move the browser forward and
backward in the history stack and discover what pages the user has visited.
The navigator object represents the browser itself and contains useful details of what type
of browser, version, and operating system the user has. These details enable you to write
pages dealing with various types of browsers, even where they may be incompatible.
The screen object contains information about the display capabilities of the user's computer.
The document object is one of the most important objects. It's an object representation of
your page and contains all the elements, also represented by objects, within that page. The
differences between the various browsers are particularly prominent here, but similarities
exist between the browsers that enable you to write cross‐browser code.
The document object contains three properties that are actually collections. These are the
links , images , and forms collections. Each contains all the objects created by the <a/> ,
<img/> , and <form/> elements on the page, and it's a way of accessing those elements.
The images collection contains an img object for each <img/> element on the page. You
found that even after the page has loaded, you can change the properties of images. For
example, you can make the image change when clicked. The same principles for using the
images collection apply to the links collection.
Finally, you looked at how you can check what type of browser the user has, thereby giving
you the power to use new features without causing errors in older browsers. You also learned
how to sniff the browser with the navigator object's appName and userAgent properties,
and how unreliable that information can be.
That's it for this chapter. In the next chapter, you move on to the more exciting document object
model, where you can access and manipulate the elements in your page.
Search WWH ::




Custom Search