Represents an open window in the browser.
Members Table
The following table lists the members exposed by the
window
object.
Show:
|
Property | Description |
---|
closed |
Retrieves whether the referenced window is closed. | defaultStatus |
Sets or retrieves the default message displayed in the status bar at the bottom of the window. | dialogArguments |
Gets the variable or array of variables passed into the modal dialog window. | dialogHeight |
Sets or gets the height of the modal dialog window. | dialogLeft |
Sets or gets the left coordinate of the modal dialog window. | dialogTop |
Sets or gets the top coordinate of the modal dialog window. | dialogWidth |
Sets or gets the width of the modal dialog window. | frameElement |
Retrieves the frame or iframe object that is hosting the window in the parent document. | length |
Sets or retrieves the number of objects in a collection. | name |
Sets or retrieves a value that indicates the window name. | offscreenBuffering |
Sets or retrieves whether objects are drawn offscreen before being made visible to the user. | opener |
Sets or retrieves a reference to the window that created the current window. | parent |
Retrieves the parent of the window in the object hierarchy. | returnValue |
Sets or gets the value returned from the modal dialog window. | screenLeft |
Retrieves the x-coordinate of the upper left-hand corner of the browser's client area, relative to the upper left-hand corner of the screen. | screenTop |
Retrieves the y-coordinate of the top corner of the browser's client area, relative to the top corner of the screen. | self |
Retrieves a reference to the current window or frame. | status |
Sets or retrieves the message in the status bar at the bottom of the window. | top |
Retrieves the topmost ancestor window. | XMLHttpRequest |
Instantiates the XMLHttpRequest object for the window. |
Collection | Description |
---|
frames |
Retrieves a collection of all window objects defined by the given document or defined by the document associated with the given window. |
Event | Description |
---|
onactivate |
Fires when the object is set as the active element. | onafterprint |
Fires on the object immediately after its associated document prints or previews for printing. | onbeforedeactivate |
Fires immediately before the activeElement is changed from the current object to another object in the parent document. | onbeforeprint |
Fires on the object before its associated document prints or previews for printing. | onbeforeunload |
Fires prior to a page being unloaded. | onblur |
Fires when the object loses the input focus. | oncontrolselect |
Fires when the user is about to make a control selection of the object. | ondeactivate |
Fires when the activeElement is changed from the current object to another object in the parent document. | onerror |
Fires when an error occurs during object loading. | onfocus |
Fires when the object receives focus. | onhelp |
Fires when the user presses the F1 key while the browser is the active window. | onload |
Fires immediately after the browser loads the object. | onmoveend |
Fires when the object stops moving. | onmovestart |
Fires when the object starts to move. | onresize |
Fires when the size of the object is about to change. | onresizeend |
Fires when the user finishes changing the dimensions of the object in a control selection. | onscroll |
Fires when the user repositions the scroll box in the scroll bar on the object. | onunload |
Fires immediately before the object is unloaded. |
Method | Description |
---|
alert |
Displays a dialog box containing an application-defined message. | attachEvent |
Binds the specified function to an event, so that the function gets called whenever the event fires on the object. | blur |
Causes the element to lose focus and fires the onblur event. | clearInterval |
Cancels the interval previously started using the setInterval method. | clearTimeout |
Cancels a time-out that was set with the setTimeout method. | close |
Closes the current browser window or HTML Application (HTA). | confirm |
Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons. | createPopup |
Creates a popup window. | detachEvent |
Unbinds the specified function from the event, so that the function stops receiving notifications when the event fires. | execScript |
Executes the specified script in the provided language. | focus |
Causes the element to receive the focus and executes the code specified by the onfocus event. | moveBy |
Moves the screen position of the window by the specified x and y offset values. | moveTo |
Moves the screen position of the upper-left corner of the window to the specified x and y position. | navigate |
Loads the specified URL to the current window. | open |
Opens a new window and loads the document specified by a given URL. | print |
Prints the document associated with the window. | prompt |
Displays a dialog box that prompts the user with a message and an input field. | resizeBy |
Changes the current size of the window by the specified x- and y-offset. | resizeTo |
Sets the size of the window to the specified width and height values. | scroll |
Causes the window to scroll to the specified x- and y-offset at the upper-left corner of the window. | scrollBy |
Causes the window to scroll relative to the current scrolled position by the specified x- and y-pixel offset. | scrollTo |
Scrolls the window to the specified x- and y-offset. | setActive |
Sets the object as active without setting focus to the object. | setInterval |
Evaluates an expression each time a specified number of milliseconds has elapsed. | setTimeout |
Evaluates an expression after a specified number of milliseconds has elapsed. | showHelp |
Displays a Help file. This method can be used with Microsoft HTML Help. | showModalDialog |
Creates a modal dialog box that displays the specified HTML document. | showModelessDialog |
Creates a modeless dialog box that displays the specified HTML document. |
Object | Description |
---|
clientInformation |
Contains information about the browser. | clipboardData |
Provides access to predefined clipboard formats for use in editing operations. | document |
Represents the HTML document in a given browser window. | event |
Represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons. | external |
Allows access to an additional object model provided by host applications of the Microsoft Internet Explorer browser components. | history |
Contains information about the URLs visited by the client. | location |
Contains information about the current URL. | navigator |
Contains information about the browser. | screen |
Contains information about the client's screen and rendering capabilities. |
|
Remarks
You can use the window object to retrieve information about the state of the window. You also can use this object to gain access to the document in the window, to the events that occur in the window, and to features of the browser that affect the window.
Typically, the browser creates one window object when it opens an HTML document. However, if a document defines one or more frames (that is, contains one or more frame or iframe tags), the browser creates one window object for the original document and one additional window object for each frame. These additional objects are child windows
of the original window and can be affected by actions that occur in the original. For example, closing the original window causes all child windows to close. You can also create new windows (and corresponding window objects) using methods such as open, showModalDialog, and showModelessDialog.
You can apply any window property, method, or collection to any variable or expression that evaluates to a window object, regardless of how that window was created. Additionally, you can access all window properties, methods, and collections in the current window by using the property, method, or collection name directly—that is, without prefixing it with an expression that evaluates to the current window object. However, to help make more readable code and to avoid potential ambiguities, many authors use the window keyword when accessing window properties, methods, and collections for the current window. This keyword always refers to the current window.
Note The window's properties, methods, and collection names are reserved keywords and cannot be used as the names of variables or routines.
The following table lists pertinent information for some of the properties of the window object.
Examples
This example displays an alert for the current window.
alert("A simple message.")
This example checks whether the current window contains child windows and, if it does, displays the names of those child windows.
if ( window.frames != null ) {
for ( i = 0; i< window.frames.length; i++ )
window.alert ("Child window " +i+ " is named "+window.frames(i).name);
}
This example shows a simple event handler function for the window's onload event. In the absence of a "window" element, the body element hosts the following window object events: onblur, onbeforeunload, onfocus, onload, and onunload.
Standards Information
There is no public standard that applies to this object.