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 |
This event is not supported for Windows Store apps using JavaScript. |
| 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. |
| 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 |
|---|---|
| addEventListener |
Registers an event handler for the specified event type. |
| 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 app without prompting the user. To the user, it appears as though the app has crashed. |
| 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. |
| 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. |
| 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. |
| msIsStaticHTML |
Returns a Boolean value indicating whether or not the given HTML string is safe. |
| msWriteProfilerMark |
Writes a profiling event. |
| navigate |
Loads the specified URL to the current window. |
| open |
Navigates the app window to the specified location. |
| postMessage |
Sends a cross-document message. |
| removeEventListener |
Removes an event handler that the addEventListener method registered. |
| 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. |
| toStaticHTML |
Removes dynamic HTML elements and attributes from an HTML fragment. |
Properties
The window object has these properties.
| Property | Description |
|---|---|
|
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 a reference to the constructor of an object. | |
|
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 a Windows Store app using JavaScript. | |
|
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. | |
|
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. | |
|
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. | |
|
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 |
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 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!');">
Build date: 11/28/2012