### Window Object

##### Description

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

> - Frame - Array of frame windows contained by a parent window. Each frame is a window that has its own properties, including a document.
> - History - History object for the current window. This object is used to access the history list from the browser.
> - Navigator - Navigator object for the current window. The navigator object contains information about the browser application.
> - Location - Location object for the current window. Provides information about the location of the window's URL.
> - Script - Scripting function defined using the SCRIPT element in the window scope.
> - Document - Document in the current window.

> 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, add a script for either the onLoad or onUnload events in the BODY tag at the top of the page. In the following example, the Foo function is called when the page is loaded:

>     <HTML>
>     ...
>     <BODY Language="VBScript" 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= "frame1" SRC="a.htm">
>       <FRAME NAME= "frame2" SRC="b.htm">
>     </FRAMESET>

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

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

> name, parent, opener, 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, opener, self, top, location, defaultStatus, status, frames, history, navigator, document

### name Property

##### Description

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

##### Syntax

> [window.]name

> Part | Description
> 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 or "null" if none.

##### Remarks

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

>     String1=name.

##### Applies To

> Window

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

> parent, opener, 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

> Part | Description
> 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, opener, self, top, location, defaultStatus, status, frames, history, navigator, document

### opener Property

##### Description

> Returns the window object of the window that opened the current window.

##### Syntax

> [window.]opener

> Part | Description
> 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 opener window.

##### Remarks

> To set the value of "String1" to be the opener of the current window, use:

>     String1=opener.name.

##### 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, document

### self Property

##### Description

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

##### Syntax

> [window.]self

> Part | Description
> 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, opener, 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

> Part | Description
> 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, opener, self, location, defaultStatus, status, frames, history, navigator, document

### location Property

##### Description

> Returns the location object for the current window. For more details, see "location Object."

##### Syntax

> [window.]location

> Part | Description
> 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, opener, self, top, defaultStatus, status, frames, history, navigator, document

### defaultStatus Property

##### Description

> Sets the default status text in the lower left portion of the status bar.

##### Syntax

> [window.]defaultStatus[=string]

> Part | Description
> 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.

##### Remarks

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

>     defaultStatus="Hello"

##### Applies To

> Window

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

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

### status Property

##### Description

> Sets the status text in the lower left part of the status bar.

##### Syntax

> [window.]status[=string]

> Part | Description
> 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.

##### Remarks

> To set the status to "Hello" use:

>     status="Hello"

##### Applies To

> Window

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

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

### frames Property

##### Description

> Returns the array of frames for the current window.

##### Syntax

> [window.]frames[integer]

> Part | Description
> 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, opener, 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

> Part | Description
> 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, opener, 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

> Part | Description
> 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, opener, 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

> Part | Description
> 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, opener, 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)

> Part | Description
> 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, opener, 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.

##### Syntax

> [bool =][window.]confirm (string)

> Part | Description
> 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, opener, self, top, location, defaultStatus, status, frames, history, navigator, document

### prompt Method

##### Description

> Prompts the user for input.

##### Syntax

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

> Part | Description
> window | Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
> prompt | 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.

##### Applies To

> Window

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

> name, parent, opener, 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][, top=pixels][, left=pixels]"]

> Part | Description
> 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 | Four other properties in this list, top, left, 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:

>     <SCRIPT LANGUAGE="VBScript">
>     	open "http://www.microsoft.com", "myWindow", "toolbar=no, location=no, directories=no"
>     </SCRIPT>

##### Applies To

> Window

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

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

### close Method

##### Description

> Closes the window.

##### Syntax

> [window.]close

> Part | Description
> 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.

##### Applies To

> Window

##### Methods

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

##### Events

> onLoad, onUnload

##### Properties

> name, parent, opener, 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, language

> Part | Description
> 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.
> language | The scripting language used. Can be "VBScript" or "Javascript."

##### 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

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

### clearTimeout Method

##### Description

> Clears the timer having a particular ID.

##### Syntax

> [window.]clearTimout ID

> Part | Description
> 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

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

### navigate Method

##### Description

> Navigates the window to a new URL.

##### Syntax

> [window.]navigate url

> Part | Description
> 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, opener, self, top, location, defaultStatus, status, frames, history, navigator, document

### Events

### onLoad Event Handler

##### Description

> Fired after all HTML has been parsed and processed.

##### Syntax

> onLoad=function-name

> Value | Description
> function-name | An object expression that evaluates to a scripting function.

##### Remarks

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

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

##### Applies To

> Window

### onUnload Event Handler

##### Description

> Fired when the contents of the window are unloaded.

##### Syntax

> onUnload=function-name

> Value | Description
> function-name | An object expression that evaluates to a scripting function.

##### Remarks

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

>     <BODY Language="VBScript" onUnload="Foo">

##### Applies To

> Window

© 1996 Microsoft Corporation