Window Object Properties

The Window object has a number of non-object properties, which we'll look at briefly in this section. In addition we’ll take a look at the Location object, since it reoccurs in other parts of the object model hierarchy. We’ll leave the other object properties until later in this chapter.

The Name Property

This property returns the name of the Window object, and is read-only. If the current Window object doesn’t have a name, it returns an empty string.

Parent, Opener, Self and Top

These properties return references to a given Window object. In this sense, they aren’t used directly, any more than the Window object itself is used directly. Instead, they’re only used as references to access other properties or methods. For example, the following code will give a syntax error:

Alert "Window.Parent is " & Window.Parent

But this code will work fine, returning the Name of the Parent window:

Alert "Window.Parent.Name is " & Window.Parent.Name

If the current Window object has a parent (like it would if it was part of a frameset), then Parent returns the Window object of the current window’s parent. If the current window doesn’t have a parent, i.e. it occupies the whole browser window, Parent returns the current window’s Window object.

Top is a bit like Parent, and they sometimes return a reference to the same object. However, there is one major difference. Top always returns a reference to the top-level frame in a frameset, while Parent only returns the Window object of the frame immediately above it.

Opener returns a reference to the Window object of the window that opened the current window, or returns nothing if the current window wasn’t opened in code (i.e. by a Window.Open statement). Finally, Self just returns a reference to the current Window object. Window and Window.Self both return the same reference.

In a simple page without frames, these properties aren’t very useful. However, as soon as we start experimenting with frames or multiple browser windows, we’ll find that these properties come in handy.

Status and defaultStatus

Both Status and defaultStatus can be used to set the text displayed in the status bar at the bottom of the browser. The code is as simple as:

Window.Status = "Display me"

and

Window.defaultStatus = "Display me"

In the current implementation of the Internet Explorer object model these properties do the same thing, and are both write-only if you’re using VBScript. This means we can set the text of the status bar, but we can’t read what’s there already, or what we’ve set it to.

© 1997 by Wrox Press. All rights reserved.