JavaScript has an intermediate layer between Core (discussed in the previous chapter) and the Document Object Model, or DOM (to be discussed in Chapters 7-10). Commonly called the Browser Object Model, or BOM, this layer is specific to JavaScript's client-side implementation, so it's not part of Core. It does not work with the HTML document, so it's not part of the DOM, either. The BOM's most important task is managing browser windows (each of which have a separate window object) and enabling communication between them. Therefore, the window object stands at the center of the BOM. Nonetheless, as you'll notice, BOM is also the catch-all category of JavaScript. There are many objects, methods, and properties that are not part of the document structure (for instance, the URL of the current page or the identification string of the browser), and these are defined on the window object. Standards-wise, BOM is a bit of a problem. Core has been standardized by ECMA, and most aspects of the DOM have been specified by W3C. In contrast, the BOM has not yet officially been defined by any standards organization, although at the time of writing, WHAT-WG is working on a specification. Fortunately, the most important BOM features were all part of the de facto Netscape 3 standard, and are therefore supported by all browsers. Site Survey is the quintessential BOM script. It's useful to compare it to the other example scripts, to highlight the difference between DOM and BOM. All the other example scripts change an HTML document; for instance, by moving HTML elements through the document (Sandwich Picker, Usable Forms), changing the styles of elements (Edit Style Sheet, Dropdown Menu, XMLHTTP Speed Meter), or checking user input in a form field (Form Validation, Textarea Maxlength). In contrast, Site Survey hardly changes anything in the document. The script sits quietly in its corner (a popup) and registers what users are doing in the site by storing the URLs of all pages they visit. Ideally, the user never notices it's there, until the script opens the survey page and politely requests the user to participate.
The core tasks of Site Survey are to remember whether users are selected for the survey and to ensure that the popup stays in contact with the main window, even when the user requests new pages. Thus, Site Survey mainly concerns itself with window-related information such as the URL of the current page or cookies associated with it. It does not work with DOM information such as the existence and value of form fields. The window object is more important to Site Survey than the document object. |