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 - the history object for the current window. This object is used to access the history list from the browser.
- Navigator - the navigator object for the current window. The navigator object contains information about the browser application.
- location - the location object for the current window. Provides information about the location of the window's URL.
- Script - any scripting function defined using the SCRIPT element in the window scope.
- Document - the 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, 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.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
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
Returns the name of the current window.
[window.]name
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns the string containing the current window name. Note that the current implementation always returns "Microsoft Internet Explorer."
To set the value of String1 to be the name of the current window, use:
String1=name.This property is read-only.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
parent, self, top, location, defaultStatus, status, frames, history, navigator, document
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.
[window.]parent
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns the window object that evaluates to the parent window.
To set the value of String1 to be the name of the parent of the current window, use:
String1=parent.Name.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, self, top, location, defaultStatus, status, frames, history, navigator, document
Returns the window object of the current window. This property is read-only.
[window.]self
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object that evaluates to the current window.
To set the value of String1 to be the name of the current window, use:
String1=self.name
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, top, location, defaultStatus, status, frames, history, navigator, document
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.
[window.]top
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object that evaluates to the topmost window.
To set the value of String1 to be the name of the topmost window, use:
String1=top.name.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, location, defaultStatus, status, frames, history, navigator, document
Returns the location object for the current window. This property is read-only. For more details, see "Location Object."
[window.]location
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object that evaluates to the location object of window.
To set the value of String1 to be the name of the URL of the current window, use:
String1=location.HRef.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, defaultStatus, status, frames, history, navigator, document
Gets or sets the default status text in the lower left portion of the status bar.
[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.
Returns the default status text.
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.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, status, frames, history, navigator, document
Gets or sets the status text in the lower left of the status bar.
[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.
Returns the current status text.
To set the status to "Hello," use:
status="Hello."Currently not implemented.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, frames, history, navigator, document
Returns the array of frames for the current window.
[window.]frames[integer]
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object expression that evaluates to the array of frames.
To set String1 to the URL of frame[0], use:
String1=parent.frames[0].location.href.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, history, navigator, document
Returns the history object of the current window. For more details on methods, properties, and events, see "history Object."
[window.]history
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object expression that evaluates to a history object.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, navigator, document
Returns the navigator object of the current window. For more details on methods, properties, and events, see "navigator Object."
[window.]navigator
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object expression that evaluates to a navigator object.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, document
Returns the document object of the current window. For more details on methods, properties, and events, see "document Object."
[window.]document
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object expression that evaluates to a document object.
alert, confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator
This section describes the methods for the window object.
Displays an alert message box.
[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.
The following example would display an alert that contained the string "Hello World":
Alert "Hello World"
confirm, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
Displays a message box that allows the user to select OK or Cancel and returns either TRUE or FALSE.
[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.
Returns the user response: TRUE if the user pressed OK; FALSE if not.
The following example would display a message box that contained the string "Do you want to continue?":
x=Confirm "Do you want to continue?"
alert, prompt, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
Prompts the user for input.
[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. 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.
Returns the user input.
Not implemented in current build.
alert, confirm, open, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
Creates a new window.
[newwindow = ][window.]open url, target, ["[toolbar=bool] [, location=bool][, directories=bool][, status=bool][, menubar=bool][, scrollbars=bool][, resizeable=bool][, width=pixels][, height=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 Two other properties in this list, width and height, have values in pixels.
Returns an object expression that evaluates to the created window object.
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.
alert, confirm, prompt, close, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
Closes the window.
[window.]close
Part Description window Optional. An object expression that evaluates to a window object. If omitted, the current script window is used.
Returns an object expression that evaluates to the indexed frame.
Note: This feature is not currently implemented in Internet Explorer.
alert, confirm, prompt, open, setTimeout, clearTimeout, navigate
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
Sets a timer to call a function after a specified number of milliseconds.
ID = [window.]setTimeout expression, msec
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.
Returns the ID of the timer object. This can be used to cancel the timer using the clearTimeout method.
To call Button1.Click after 100 milliseconds, use:
MyID = setTimeout ("Button1.Click", 100).
parent, self, top, location, defaultStatus, status, frames, name, history, navigator, document
Clears the timer having a particular ID.
[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.
To clear the timer with ID=MyID, use.
clearTimeout MyID
parent, self, top, location, defaultStatus, status, frames, name, history, navigator, document
Navigates the window to a new URL.
[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.
alert, confirm, prompt, open, close, setTimeout, clearTimeout
name, parent, self, top, location, defaultStatus, status, frames, history, navigator, document
Fired when the contents of the window are loaded.
onLoad=function-name
Value Description function-name An object expression that evaluates to a scripting function.
To call the VBS function Foo when the page is loaded, use:
<BODY Language="VBS" onLoad="Foo">
Fired when the contents of the window are unloaded.
onUnload=function-name
Value Description function-name An object expression which evaluates to a scripting function.
To call the VBS function Foo when the page is unloaded, use:
<BODY Language="VBS" onUnload="Foo">[<window.>]Navigate url