window object
Represents an open window.
Members
The window object has these types of members:
Events
The window object has these events.
| Event | Description |
|---|---|
| abort |
Fires when the user aborts the download. |
| afterprint |
Fires on the object immediately after its associated document prints or previews for printing. |
| beforeprint |
Fires on the object before its associated document prints or previews for printing. |
| beforeunload |
Fires prior to a document being unloaded. |
| blur |
Fires when the object loses the input focus. |
| canplay |
Occurs when playback is possible, but would require further buffering. |
| canplaythrough |
Occurs when playback to end is possible without requiring a stop for further buffering. |
| change |
Fires when the contents of the object or selection have changed. |
| click |
Fires when the user clicks the left mouse button on the object. |
| contextmenu |
Fires when the user clicks the right mouse button in the client area, opening the context menu. |
| dblclick |
Fires when the user double-clicks the object. |
| drag |
Fires on the source object continuously during a drag operation. |
| dragend |
Fires on the source object when the user releases the mouse at the close of a drag operation. |
| dragenter |
Fires on the target element when the user drags the object to a valid drop target. |
| dragleave |
Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. |
| dragover |
Fires on the target element continuously while the user drags the object over a valid drop target. |
| dragstart |
Fires on the source object when the user starts to drag a text selection or selected object. |
| drop |
Fires on the target object when the mouse button is released during a drag-and-drop operation. |
| durationchange |
Occurs when the duration attribute is updated. |
| emptied |
Occurs when the media element is reset to its initial state. |
| ended |
Occurs when the end of playback is reached. |
| error |
Fires when an error occurs during object loading. |
| focus |
Fires when the object receives focus. |
| focusin |
Fires for an element just prior to setting focus on that element. |
| focusout |
Fires for the current element with focus immediately after moving focus to another element. |
| hashchange |
Raised when there are changes to the portion of a URL that follows the number sign (#). This event is not supported for Windows Store apps using JavaScript. |
| help |
Fires when the user presses the F1 key while the client is the active window. |
| input |
Occurs when the text content of an element is changed through the user interface. |
| keydown |
Fires when the user presses a key. |
| keypress |
Fires when the user presses an alphanumeric key. |
| load |
Fires immediately after the client loads the object. |
| loadeddata |
Occurs when media data is loaded at the current playback position. |
| loadedmetadata |
Occurs when the duration and dimensions of the media have been determined. |
| loadstart |
Occurs when Internet Explorer begins looking for media data. |
| message |
Fires when the user sends a cross-document message or a message is sent from a Worker with postMessage. |
| mousedown |
Fires when the user clicks the object with either mouse button. |
| mousemove |
Fires when the user moves the mouse over the object. |
| mouseout |
Fires when the user moves the mouse pointer outside the boundaries of the object. |
| mouseover |
Fires when the user moves the mouse pointer into the object. |
| mouseup |
Fires when the user releases a mouse button while the mouse is over the object. |
| mousewheel |
Fires when the wheel button is rotated. |
| MSPointerCancel |
Fires when the system cancels a pointer event. |
| offline |
Raised when Internet Explorer is working offline. This event is not supported for Windows Store apps using JavaScript. |
| onbeforedeactivate |
Fires immediately before the activeElement is changed from the current object to another object in the parent document. |
| onkeyup |
Fires when the user releases a key. |
| online |
Raised when Internet Explorer is working online. This event is not supported for Windows Store apps using JavaScript. |
| onselect |
Fires when the current selection changes. |
| pause |
Occurs when playback is paused. |
| play |
Occurs when the play method is requested. |
| playing |
Occurs when the audio or video has started playing. |
| progress |
Occurs to indicate progress while downloading media data. |
| ratechange |
Occurs when the playback rate is increased or decreased. |
| reset |
Fires when the user resets a form. |
| scroll |
Fires when the user repositions the scroll box in the scroll bar on the object. |
| seeked |
Occurs when the seek operation ends. |
| seeking |
Occurs when the current playback position is moved. |
| stalled |
Occurs when the download has stopped. |
| storage |
Fires when a Web Storage area is updated. |
| suspend |
Occurs if the load operation has been intentionally halted. |
| timeupdate |
Occurs to indicate the current playback position. |
| unload |
Fires immediately before the object is unloaded. |
| volumechange |
Occurs when the volume is changed, or playback is muted or unmuted. |
| waiting |
Occurs when playback stops because the next frame of a video resource is not available. |
Methods
The window object has these methods.
| Method | Description |
|---|---|
| AddChannel |
Obsolete. Presents a dialog box that enables the user to add the specified channel, or to change the channel URL, if it is already installed. |
| addEventListener |
Registers an event handler for the specified event type. |
| AddSearchProvider |
Deprecated. Adds a search provider to the registry. |
| AddService |
Deprecated. User initiated action to add a service. |
| AddToFavoritesBar |
Deprecated. Adds a URL to the Favorites Bar. |
| alert |
Displays a dialog box containing an application-defined message. This method is not supported for Windows Store apps using JavaScript. |
| 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. |
| clearImmediate |
Cancels a function request created with setImmediate. |
| 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 HTA. Closes the app without prompting the user. To the user, it appears as though the app has crashed. |
| confirm |
Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons. This method is not supported for Windows Store apps using JavaScript. |
| ContentDiscoveryReset |
Resets the list of feeds, search providers, and Web Slices associated with the page. |
| create |
Creates a new img element of the specified width and height. This method cannot be called directly. See Image object. |
| create |
Initializes a new option element. This method cannot be called directly. See Option object. |
| createPopup |
Creates a popup window object. |
| detachEvent |
Unbinds the specified function from the event, so that the function stops receiving notifications when the event fires. |
| dispatchEvent |
Sends an event to the current element. |
| 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. |
| getComputedStyle |
Returns a currentStyle object containing the CSS settings that are applied to the specified element or a pseudo-element related to the specified element. |
| getSelection |
Returns an object that represents the current selection of the document. |
| InPrivateFilteringEnabled |
Detects whether the user has enabled InPrivate Filtering. |
| IsSearchProviderInstalled |
Deprecated. Determines if a search provider has been installed for the current user and whether it is set as default. |
| IsServiceInstalled |
Deprecated. Check if a service is already installed. |
| item |
Retrieves an object from various collections, including the all collection. |
| matchMedia |
Accepts a string containing one or more media queries, and returns a MediaQueryList object. |
| 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. |
| msActiveXFilteringEnabled |
Determines whether ActiveX Filtering is enabled by the user. |
| msAddSiteMode |
Creates a pinned site shortcut to the current webpage on the Windows Start menu. This method is not supported for Windows Store apps using JavaScript. |
| msAddTrackingProtectionList |
Adds an external Tracking Protection list. |
| msIsSiteMode |
Determines whether the current page was launched as a pinned site. |
| msIsSiteModeFirstRun |
Determines whether a pinned site was launched for the first time. |
| msIsStaticHTML |
Returns a Boolean value indicating whether or not the given HTML string is safe. |
| msSiteModeActivate |
Flashes the pinned site taskbar button. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeAddButtonStyle |
Defines an alternate icon image and tooltip for the specified button. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeAddJumpListItem |
Adds a new entry to the Jump List of a taskbar button. |
| msSiteModeAddThumbBarButton |
Adds a button to the Thumbnail Toolbar. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeClearIconOverlay |
Removes the icon overlay from the taskbar button. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeClearJumpList |
Deletes the Jump List. |
| msSiteModeCreateJumpList |
Creates a new group of items on the Jump List. |
| msSiteModeSetIconOverlay |
Adds an icon overlay to the pinned site taskbar button. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeShowButtonStyle |
Changes the icon image and tooltip of a Thumbnail Toolbar button. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeShowJumpList |
Shows updates to the list of items in a Jump List. |
| msSiteModeShowThumbBar |
Enables the Thumbnail Toolbar in the thumbnail preview of a pinned site. This method is not supported for Windows Store apps using JavaScript. |
| msSiteModeUpdateThumbBarButton |
Changes the state of a Thumbnail Toolbar button. This method is not supported for Windows Store apps using JavaScript. |
| msTrackingProtectionEnabled |
Determines whether any Tracking Protection lists are enabled by the user. |
| msWriteProfilerMark |
Writes a profiling event. |
| navigate |
Loads the specified URL to the current window. |
| open |
Opens a new window and loads the document specified by a given URL. Navigates the app window to the specified location. |
| postMessage |
Sends a cross-document message. |
|
Prints the document associated with the window. | |
| prompt |
Displays a dialog box that prompts the user with a message and an input field. |
| removeEventListener |
Removes an event handler that the addEventListener method registered. |
| 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. |
| setImmediate |
Requests that a function be called when current or pending tasks are complete, such as events or screen updates. |
| 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. |
| toStaticHTML |
Removes dynamic HTML elements and attributes from an HTML fragment. |
Properties
The window object has these properties.
| Property | Description |
|---|---|
|
Returns a null value. | |
|
Obsolete. Returns a timestamp of the start time of the current refresh interval, such that multiple animations can be synchronized with each other. | |
|
Returns an ApplicationCache object. | |
|
Retrieves whether the referenced window is closed. | |
|
Returns the windows console object to use to send messages. | |
|
Returns a reference to the constructor of an object. | |
|
Sets or retrieves the default message displayed in the status bar at the bottom of the window. | |
|
Gets the variable or array of variables passed into the modal dialog window. | |
|
Sets or gets the height of the modal dialog window. | |
|
Sets or gets the left coordinate of the modal dialog window. | |
|
Sets or gets the top coordinate of the modal dialog window. | |
|
Sets or gets the width of the modal dialog window. | |
|
Retrieves the frame or iframe object that is hosting the window in the parent document. | |
|
Returns whether a webpage is visible. | |
|
Allows access to the Indexed Database API, as implemented by Internet Explorer 10. | |
|
Gets the height of the window, excluding user interface elements, such as the window frame, toolbars, and so on. | |
|
Gets the width of the window, excluding user interface elements, such as the window frame. | |
|
Sets or retrieves the number of objects in a collection. | |
|
Retrieves the Web Storage area specific to the current document. | |
|
Retrieves the maximum number of concurrent connections to a Web server. | |
|
Sets or retrieves a value that indicates the window name. | |
|
Sets or retrieves whether objects are drawn offscreen before being made visible to the user. | |
|
Sets or retrieves a reference to the window that created the current window. | |
|
Gets the height of the window, including user interface elements, such as the window frame, toolbars, and so on. | |
|
Gets the width of the window, including user interface elements, such as the window frame. | |
|
Gets the distance, in pixels, that a document has scrolled horizontally. | |
|
Gets the distance, in pixels, that a document has scrolled vertically. | |
|
Retrieves the parent of the window in the object hierarchy. | |
|
Provides access to timing related information regarding navigation and performance for the document that is loaded into the window object. | |
|
Sets or gets the value returned from the modal dialog window. This property is not supported for Windows Store apps using JavaScript. | |
|
Retrieves the x-coordinate of the upper left-hand corner of the window frame, relative to the upper left-hand corner of the screen. | |
|
Retrieves the y-coordinate of the top corner of the client area, relative to the top corner of the screen. | |
|
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenX. | |
|
Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenY. | |
|
Retrieves a reference to the current window or frame. | |
|
Retrieves the Web Storage area for the session. | |
|
Sets or retrieves the message in the status bar at the bottom of the window. | |
|
Gets a StyleMedia object that contains methods and properties. These methods and properties determine the media types that are supported by the object that displays the document object. | |
|
Retrieves the topmost ancestor window. | |
| Instantiates the XMLHttpRequest object for the window. |
Standards information
There are no standards that apply here.
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 other factors that affect the window.
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.
| Property | Method | Description |
|---|---|---|
| opener | open | The opener property is available only from a document opened using the window.open method. |
| parent, top | None | The parent and top properties are available for a window opened inside a frame or iframe. The two properties return the topmost parent and immediate parent, respectively. |
| parent, top | open | The parent and top properties are available for a window opened via the open method or as a dialog and returns the current window. |
| length | None | Regardless of how the window is opened, the length property returns the number of frames in a window. |
| dialogArguments, dialogHeight, dialogLeft, dialogTop, dialogWidth, returnValue | showModalDialog and showModelessDialog | These properties are available only for windows created using the two methods listed—showModalDialog and showModelessDialog |
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 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.
Unsupported window members for Windows Store apps using JavaScript
These window members are unavailable to Windows Store apps using JavaScript:
- AddChannel
- AddToFavoritesBar
- alert
- confirm
- ContentDiscoveryReset
- createPopup
- external.navigateAndFind
- moveBy
- moveTo
- prompt
- resizeBy
- resizeTo
- showModalDialog
- showHelp
- showModelessDialog
In Windows CE, the document object is not available through scripting for a window object opened using the open method.
Examples
This example checks whether the current window contains child windows and, if it does, displays the names of those child windows in a debugging console window (see F12 Developer Tools for more information).
if ( window.frames != null ) {
for ( i = 0; i < window.frames.length; i++ )
console.log("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.
<body onload="console.log('Document is loaded!');">
Send comments about this topic to Microsoft
Build date: 11/27/2012
