The Window Object

The Window object is the object that represents the Internet Explorer. The properties, methods, and events defined in Tables 3-3, 3-4, and 3-5 can be called directly in VBScript without qualification—meaning that the Window object does not need to be specified. The following code shows an example using the Confirm method:

<SCRIPT LANGUAGE="VBScript">
    MyVar = Confirm ("Are you sure?")
</SCRIPT> 

Table 3-3.Window Object Properties

Property Type Description Usage
Name String Returns the name of the current window. MsgBox Name
Parent Object Returns a reference to the Parent Set object. MyObject=Parent
Self Object Returns a reference to the Window object itself. Set MyObject=Self
Top Object Returns a reference to the topmost Window object. Set MyObject=Top
Location Object Returns a reference to the Location object. Set MyObject= Location
DefaultStatus String Returns or sets the text in the lower left corner of the status bar. (At this writing, this property does not set the specified string to be the default status message. Therefore, it is the same as calling Status.) DefaultStatus="Ready"
Status String Returns or sets the text in the lower left corner of the status bar. Status="Busy"
Frames Object Returns a reference to the Frames array. Set MyObject= Frames(1)
History Object Returns a reference to the History object of the current window. Set MyObject=History
Navigator Object Returns a reference to the Navigator object of the current window. Set MyObject= Navigator
Document Object Returns a reference to the Document object of the current window. Set MyObject= Document

Table 3-4.Window Object Methods

Method Return Type Description Usage
Alert None Displays an OK message box. Alert "Stop that!"
Confirm Boolean Displays an OK/Cancel message box and returns a Boolean value. True if user clicked on OK; False if not. MyVar=Confirm ("Are you sure?")
Prompt String Displays an OK/Cancel input box that returns the text in the input box. The message and the initial text in the input boxcan be specified. MyVar=Prompt ("Enter your name", "name")
Open Object Opens a new window. open("url", "windowName", "windowFeatures", width, height)
Close None Closes the window. Close
SetTimeout Long Executes the code contained in the string after msec milliseconds have elapsed. MyID=SetTimeout ("string", msec)
ClearTimeout None Clears the timer specified. ClearTimeout(MyID)
Navigate None Jumps to a specified URL. Navigate "http://www.vb-bootcamp.com"

Table 3-5.Window Object Events

Event Arguments Description Usage
OnLoad None Fires when page is loaded <BODY OnLoad="MySub">
OnUnload None Fires when page is unloaded <BODY OnUnload="MySub">

© 1996 by Scot Hillier. All rights reserved.