Window Object


window Object

Description

The top level object in the scripting object model is a window. Every window contains:

The window object represents the Internet Explorer window and its methods and properties. Methods and properties of the window object can be called by scripts directly. This means that if you wanted to get the name of the current page, you would use the following script (Notice that the property name does not need a prefix):


<script language="VBScript">
     '...
     string1=name          - get the name of the current window
     alert string1          - display that name as an alert
     '...
</script> 

However, you can access the properties of other window objects without explicitly mentioning the window. For example, to get the name of the current window's parent, you would use:


<script language="VBScript">
     '...
     string1=parent.name       - get the name of the parent window
     '...
</script> 

window events can be hooked to scripts using extensions to the BODY tag. To add scripts to a window event, in the BODY tag at the top of the page, add a script for either the onLoad or onUnload events. In the following example, the Foo function is called when the page is loaded:


<HTML>
...
<BODY Language="VBS" onLoad="Foo">
...
<SCRIPT language="VBScript">
... 
Sub Foo
	MsgBox "This is sub foo"
End Sub
... 
</SCRIPT>
....
</BODY></HTML>

To access a window by name, the window must be given a name. This can happen in three ways: by using the window.open method, by creating the window with a name using the FRAMESET element, or by creating the window with a URL using the TARGET attribute.

The following examples all create a window named foo with contents a.htm.

<SCRIPT Language="VBScript">
window.open ( "a.htm", "foo");
</SCRIPT>

<FRAMESET cols = "200, *" frameborder=0>
  <FRAME name = "foo" src="a.htm">
  <FRAME name = "bar" src="b.htm">
</FRAMESET>

<A HREF="a.htm" TARGET = "foo">Click here to see a.htm in window foo.</A>

The current implementation of Internet Explorer does not support window.open.

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


Properties

window properties can be referenced directly in the scripting language. Consequently, all window properties are reserved words and cannot be used as variable names in procedures. The following window properties are used:

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


name Property

Description

Returns the name of the current window.

Syntax

[window.]name

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns the string containing the current window name. Note that the current implementation always returns "Microsoft Internet Explorer."

Remarks

To set the value of String1 to be the name of the current window, use:


String1=name.

This property is read-only.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

parent, self, top, location, defaultStatus, status, frames, history, navigator, document


parent Property

Description

Returns the window object of the window's parent. This property is read-only. The parent of the window is the containing frame. If the current window has no containing frame windows, then the parent evaluates to the current window.

Syntax

[window.]parent

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns the window object that evaluates to the parent window.

Remarks

To set the value of String1 to be the name of the parent of the current window, use:


String1=parent.Name.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, self, top, location, defaultStatus, status, frames, history, navigator, document


self Property

Description

Returns the window object of the current window. This property is read-only.

Syntax

[window.]self

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object that evaluates to the current window.

Remarks

To set the value of String1 to be the name of the current window, use:


String1=self.name

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, top, location, defaultStatus, status, frames, history, navigator, document


top Property

Description

Returns the window object of the topmost window. This property is read-only. The topmost window is the containing window of all frames in the current browser instance.

Syntax

[window.]top

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object that evaluates to the topmost window.

Remarks

To set the value of String1 to be the name of the topmost window, use:


String1=top.name.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, location, defaultStatus, status, frames, history, navigator, document


location Property

Description

Returns the location object for the current window. This property is read-only. For more details, see "Location Object."

Syntax

[window.]location

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object that evaluates to the location object of window.

Remarks

To set the value of String1 to be the name of the URL of the current window, use:


String1=location.HRef.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, defaultStatus, status, frames, history, navigator, document


defaultStatus Property

Description

Gets or sets the default status text in the lower left portion of the status bar.

Syntax

[window.]defaultStatus[=string]

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
String Optional. Sets the default status text to the value of String.

Return Value

Returns the default status text.

Remarks

To set the default status to "Hello," use:


defaultStatus="Hello"

Note that this property does not currently set the default status message, so it is the same as calling status.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, status, frames, history, navigator, document


status Property

Description

Gets or sets the status text in the lower left of the status bar.

Syntax

[window.]status[=string]

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
String Optional. Sets the status text to the value of String.

Return Value

Returns the current status text.

Remarks

To set the status to "Hello," use:


status="Hello."

Currently not implemented.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, frames, history, navigator, document


frames Property

Description

Returns the array of frames for the current window.

Syntax

[window.]frames[integer]

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object expression that evaluates to the array of frames.

Remarks

To set String1 to the URL of frame[0], use:


String1=parent.frames[0].location.href.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, history, navigator, document


history Property

Description

Returns the history object of the current window. For more details on methods, properties, and events, see "history Object."

Syntax

[window.]history

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object expression that evaluates to a history object.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, navigator, document


navigator Property

Description

Returns the navigator object of the current window. For more details on methods, properties, and events, see "navigator Object."

Syntax

[window.]navigator

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object expression that evaluates to a navigator object.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, document


document Property

Description

Returns the document object of the current window. For more details on methods, properties, and events, see "document Object."

Syntax

[window.]document

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object expression that evaluates to a document object.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator


Methods

This section describes the methods for the window object.


alert Method

Description

Displays an alert message box.

Syntax

[window.]alert string

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
String A string containing the text to display in the message box.

Remarks

The following example would display an alert that contained the string "Hello World":


Alert "Hello World"

Applies To

Window

Methods

confirm, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


confirm Method

Description

Displays a message box that allows the user to select OK or Cancel and returns either TRUE or FALSE.

Syntax

[bool =][window.]confirm string

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
String A string containing the text to display in the message box.

Return Value

Returns the user response: TRUE if the user pressed OK; FALSE if not.

Remarks

The following example would display a message box that contained the string "Do you want to continue?":

x=Confirm "Do you want to continue?"

Applies To

Window

Methods

alert, prompt, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


prompt Method

Description

Prompts the user for input.

Syntax

[string =][window.]prompt [prompt] [, default]

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
String Optional. A string containing the text to display in the message box.
default Optional. A string containing the default text to display in the input field.

Return Value

Returns the user input.

Not implemented in current build.

Applies To

Window

Methods

alert, confirm, open, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


open Method

Description

Creates a new window.

Syntax

[newwindow = ][window.]open url, target, ["[toolbar=bool] [, location=bool][, directories=bool][, status=bool][, menubar=bool][, scrollbars=bool][, resizeable=bool][, width=pixels][, height=pixels]"]

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
url A string containing a correctly parsed URL. The URL is parsed identically to a link--both relative and absolute paths are supported.
target A string containing the name of the target window. If a window with this name already exists, the existing window is reused with the new URL. If the window does not exist, a new window is created with that name. Note that this works identically to the TARGET attribute of an HREF in HTML.
bool The remaining window properties are passed as a comma-separated list. Most of these can be set to Boolean values, either yes or no [1 or 0]. These properties are toolbar, location, directories, status, menubar, scrollbars, and resizeable.
pixels Two other properties in this list, width and height, have values in pixels.

Return Value

Returns an object expression that evaluates to the created window object.

Remarks

The following example would create a new window:

 open "http://www.microsoft.com", "myWindow", "toolbar=no, location=no, directories=no"

Note: This feature is not currently implemented in Internet Explorer.

Applies To

Window

Methods

alert, confirm, prompt, close, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


close Method

Description

Closes the window.

Syntax

[window.]close

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.

Return Value

Returns an object expression that evaluates to the indexed frame.

Remarks

Note: This feature is not currently implemented in Internet Explorer.

Applies To

Window

Methods

alert, confirm, prompt, open, setTimeout, clearTimeout, navigate

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


setTimeout Method

Description

Sets a timer to call a function after a specified number of milliseconds.

Syntax

ID = [window.]setTimeout expression, msec

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Expression An object expression that evaluates to a function or object property. This function is called when the Timeout is set.
MSec The number of milliseconds that passes before the expression is evaluated.

Return Value

Returns the ID of the timer object. This can be used to cancel the timer using the clearTimeout method.

Remarks

To call Button1.Click after 100 milliseconds, use:


MyID = setTimeout ("Button1.Click", 100).

Applies To

Window

Methods

alert, confirm, prompt, open, close, clearTimeout, navigate

Events

onLoad, onUnload

Properties

parent, self, top, location, defaultStatus, status, frames, name, history, navigator, document


clearTimeout Method

Description

Clears the timer having a particular ID.

Syntax

[window.]clearTimout ID

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
ID The ID of the timer to be cleared. If there is no timer with this ID, the function does nothing.

Remarks

To clear the timer with ID=MyID, use.


clearTimeout MyID

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, navigate

Events

onLoad, onUnload

Properties

parent, self, top, location, defaultStatus, status, frames, name, history, navigator, document


navigate Method

Description

Navigates the window to a new URL.

Syntax

[window.]navigate url

PartDescription
window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
url A string containing a valid URL. The URL can be either relative or absolute.

Applies To

Window

Methods

alert, confirm, prompt, open, close, setTimeout, clearTimeout

Events

onLoad, onUnload

Properties

name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document


Events


onLoad Event

Description

Fired when the contents of the window are loaded.

Syntax

onLoad=function-name

ValueDescription
function-name An object expression that evaluates to a scripting function.

Remarks

To call the VBS function Foo when the page is loaded, use:


<BODY Language="VBS" onLoad="Foo">

Applies To

Window


onUnload Event

Description

Fired when the contents of the window are unloaded.

Syntax

onUnload=function-name

ValueDescription
function-name An object expression which evaluates to a scripting function.

Remarks

To call the VBS function Foo when the page is unloaded, use:

<BODY Language="VBS" onUnload="Foo">[<window.>]Navigate url

Applies To

Window

© 1996 Microsoft Corporation