Java Reference
In-Depth Information
The BOM has a hierarchy. At the very top of this hierarchy is the window object. You can think of this as
representing the frame of the browser and everything associated with it, such as the scrollbars, navigator
bar icons, and so on.
Contained inside the window frame is the page. The page is represented in the BOM by the document
object. You can see these two objects represented in Figure 6-2.
Browser window or
frame, represented in
the BOM by the window
object
HTML page,
represented in the BOM
by the document object
Figure 6-2
Now let's look at each of these objects in more detail.
The window Object
The window object represents the browser's frame or window, in which your web page is contained. To
some extent, it also represents the browser itself and includes a number of properties that are there simply
because they don't fi t anywhere else. For example, via the properties of the window object, you can fi nd
out what browser is running, the pages the user has visited, the size of the browser window, the size of
the user's screen, and much more. You can also use the window object to access and change the text in
the browser's status bar, change the page that is loaded, and even open new windows.
The window object is a global object , which means you don't need to use its name to access its properties
and methods. In fact, the global functions and variables (the ones accessible to script anywhere in a page)
are all created as properties of the global object. For example, the alert() function you have been using
since the beginning of the topic is, in fact, the alert() method of the window object. Although you have
been using this simply as this:
alert(“Hello!”);
You could write this with the same, exact results:
window.alert(“Hello!”);
However, since the window object is the global object, it is perfectly correct to use the fi rst version.
 
Search WWH ::




Custom Search