The Browser Object Model

As you’ve learned and worked with ASP, you’ve come to depend on the server object model documentation a lot to answer many queries. When do we need the properties of the

Server
object? Where is that
Cookies
collection? Is it the
Response
object, the
Request
object, or both? The object model provided by ASP is how we interface with the server, and it’s of utmost importance.

As you might expect, on the client-side, the browser object model is just as important. All of the interactions between our code and the browser take place via the object model, and without a good knowledge of how it is set up, our code either won’t work as well as it could, or it won’t work at all!

For the rest of this chapter, we’ll be covering the different objects in the browser object model, explaining how they relate to each other, and showing you some more examples. We need to understand exactly why we have to say things like

Document.frmTest.txtURL.Value
.

An Overview of the Browser

In the ASP object model, there are five main objects:

Server
,
Response
,
Request
,
Session
, and
Application
. These top-level objects have properties, methods, and subordinate objects where appropriate. Although it’s set up a bit differently, the browser object model follows the same principle of providing access to the features of the browser. Instead of five separate objects, the browser has one top level object called
Window
. The rest of the browser’s objects are located beneath the
Window
object in a logical hierarchy of functionality.

The

Window
object represents the browser itself. It has a number of self-contained properties, like
status
(the current text of the status bar at the bottom of the browser) that reflect and provide access to the browser. Its methods perform operations that make sense for the browser window, like opening another window and navigating to a new page. And, last but not least, it fires events every time it finishes loading a page, or completes unloading a page in preparation for moving to a new URL or shutting down.

To script programmers, the

Window
object’s subordinate objects are just as interesting as its immediate properties, methods, and events.

*** Insert diagram from 0448 VBScript Page 148 - the object model.

*** Annotate: ' Each frame is in effect a window object ' (as in VBScript book).

Of these objects, the

Document
object is by far the most utilized by the average script developer. It provides access to objects in the page currently displayed in the browser with the
Link
,
Anchor
, and
Form
collections. If we think back to our previous series of Hello World examples, we’ll realize that we’ve been using the
Forms
collection of the
Document
object from the beginning of this chapter.

The rest of this section covers each of these elements in a bit more detail, focusing especially on the

Window
and
Document
objects.

Covering every last aspect of the scripting object model would occupy many chapters (and indeed does in many books about client-side scripting). In this chapter we’ll give an overview and cover the most important elements. For more information, please check out the Wrox Press book Instant VBScript, and the Scripting Object Model document available from Microsoft's Web site at

http://www.microsoft.com
(search for
scriptom
).

Since the

Window
object is the root of many useful objects in the object model, we’ll start by looking at it first.

© 1997 by Wrox Press. All rights reserved.