window object
Represents an open window.
Members
The window object has these types of members:
Events
The window object has these events.
| Event | Description |
|---|---|
| click |
Fires when the user clicks the left mouse button on the object. Note Starting with IE11, this event fires a MSPointerEvent object instead of MouseEvent. You can use the MouseEvent.pointerType property to determine the type of contact that the click originated from (touch, mouse, or pen).
|
| 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. |
| compassneedscalibration |
Fires whenever the device magnetometer changes to a state of unreliable or approximate accuracy. |
| contextmenu |
Fires when the user clicks the right mouse button in the client area, opening the context menu. Note Starting with IE11, this event fires a MSPointerEvent object instead of MouseEvent. You can use the MouseEvent.pointerType property to determine the type of contact that the click originated from (touch, mouse, or pen).
|
| dblclick |
Fires when the user double-clicks the object. Note Starting with IE11, this event fires a MSPointerEvent object instead of a MouseEvent. You can use the MouseEvent.pointerType property to determine the type of contact that the click originated from (touch, mouse, or pen).
|
| 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. |
| gamepadconnected |
Fires when a gamepad device is connected or activated. |
| gamepaddisconnected |
Fired when a gamepad device is disconnected. |
| gotpointercapture |
Dispatched prior to the dispatch of the first event after pointer capture is set for a pointer. |
| hashchange |
Raised when there are changes to the portion of a URL that follows the number sign (#). This event is not supported for Windows 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. |
| lostpointercapture |
Dispatched after pointer capture is released for a pointer. |
| 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. |
| MSPointerHover |
Event that is triggered when a contact (normally a pen) moves over an element without touching the surface. |
| offline |
Raised when Internet Explorer is working offline. This event is not supported for Windows 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 apps using JavaScript. |
| onselect |
Fires when the current selection changes. |
| ontouchcancel |
Event indicating that the touch point has been canceled/disrupted. |
| ontouchend |
Event indicating that the touch point has ceased to exist. |
| ontouchmove |
Event indicating that the touch point has moved along the touch surface. |
| ontouchstart |
Event indicating that the user has touched the surface of a touch capable device. |
| orientationchange |
Fires when the device is rotated. |
| pause |
Occurs when playback is paused. |
| play |
Occurs when the play method is requested. |
| playing |
Occurs when the audio or video has started playing. |
| pointercancel |
Dispatched when either (1) the system has determined that a pointer is unlikely to continue to produce events (for example, due to a hardware event), or (2) after having fired the pointerdown event, the pointer is subsequently used to manipulate the page viewport (for example, panning or zooming). |
| pointerdown |
Dispatched when a pointer enters the state of having a non-zero value for the buttons property. |
| pointerenter |
Dispatched when a pointing device is moved into the hit test boundaries of an element or one of its descendants, including as a result of a pointerdown event from a device that does not support hover. |
| pointerleave |
Dispatched when a pointing device is moved outside of the hit test boundaries of an element or one of its descendants, including as a result of a pointerdown event from a device that does not support hover. |
| pointermove |
Dispatched when a pointer changes coordinates, button state, pressure, tilt, or contact geometry (for example, width and height). |
| pointerout |
Dispatched when any of the following occurs:
|
| pointerover |
Dispatched when a pointing device is moved into the hit test boundaries of an element. Also dispatched prior to a pointerdown event for devices that do not support hover. |
| pointerup |
Dispatched when a pointer leaves the state of having a non-zero value for the buttons property. |
| 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 is intentionally halted. Starting in Microsoft Edge, also occurs if the media network state becomes NETWORK_IDLE. |
| 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. |
| vrdisplayconnected |
Fires when a VRDisplay is connected to the device. |
| vrdisplaydisconnected |
Fires when a VRDisplay is disconnected to the device. |
| vrdisplaypresentchange |
Fires when the presenting state of a VRDisplay changes. |
| 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 |
Warning This method has been deprecated since Internet Explorer 8 and removed from Windows 10.
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 apps using JavaScript. |
| attachEvent |
Note
attachEvent is no longer supported. Starting with IE11, use addEventListener. For info, see Compatibility changes.
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. |
| BrandImageUri |
Not supported. Retrieves the URI of an alternate product image. |
| BuildNewTabPage |
Not supported. Check user's settings to show tab list and/or activities list. |
| captureEvents |
No appreciable effect. Do not use. |
| 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 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 |
Note
createPopup is no longer supported. Starting with IE11, use a div, iframe, or other element with a relatively high z-index value. For info, see Compatibility changes.
Creates a popup window object. |
| CustomizeClearType |
Not supported. Sets a registry value to turn ClearType on or off. |
| CustomizeSettings |
Not supported. Saves the user settings from a "first run" page. |
| DefaultSearchProvider |
Not supported. Retrieves the name of the user's default search provider. |
| detachEvent |
Unbinds the specified function from the event, so that the function stops receiving notifications when the event fires. |
| DiagnoseConnection |
Not supported. Attempts to diagnose problems with the network connection. |
| dispatchEvent |
Sends an event to the current element. |
| execScript |
Note
execScript is no longer supported. Starting with IE11, use eval. For info, see Compatibility changes.
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. |
| IsSearchMigrated |
Not supported. Determines whether autosearch settings were migrated from a previous version of Internet Explorer. |
| IsSearchProviderInstalled |
Warning This method has been deprecated since Internet Explorer 8 and removed from Windows 10.
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 only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msAddTrackingProtectionList |
Adds an external Tracking Protection list. |
| msIsSiteMode |
Determines whether the current page was launched as a pinned site. This method is only supported in IE11 on Windows 10. |
| msIsSiteModeFirstRun |
Determines whether a pinned site was launched for the first time. This method is only supported in IE11 on Windows 10. |
| 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 only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeAddButtonStyle |
Defines an alternate icon image and tooltip for the specified button. This method is only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeAddJumpListItem |
Adds a new entry to the Jump List of a taskbar button. This method is only supported in IE11 on Windows 10. |
| msSiteModeAddThumbBarButton |
Adds a button to the Thumbnail Toolbar. This method is only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeClearIconOverlay |
Removes the icon overlay from the taskbar button. This method is only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeClearJumpList |
Deletes the Jump List. This method is only supported in IE11 on Windows 10. |
| msSiteModeCreateJumpList |
Creates a new group of items on the Jump List. This method is only supported in IE11 on Windows 10. |
| msSiteModeSetIconOverlay |
Adds an icon overlay to the pinned site taskbar button. This method is only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeShowButtonStyle |
Changes the icon image and tooltip of a Thumbnail Toolbar button. This method is only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeShowJumpList |
Shows updates to the list of items in a Jump List. This method is only supported in IE11 on Windows 10. |
| msSiteModeShowThumbBar |
Enables the Thumbnail Toolbar in the thumbnail preview of a pinned site. This method is only supported in IE11 on Windows 10. This method is not supported for Windows apps using JavaScript. |
| msSiteModeUpdateThumbBarButton |
Changes the state of a Thumbnail Toolbar button. This method is only supported in IE11 on Windows 10. This method is not supported for Windows 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. |
| PhishingEnabled |
Not supported. Determines whether Phishing Filter is enabled. |
| 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. |
| releaseEvents |
No appreciable effect. Do not use. |
| 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. |
| RunOnceHasShown |
Not supported. Determines whether the "first run" page has been shown. |
| RunOnceRequiredSettingsComplete |
Not supported. Sets a registry value to indicate whether the "first run" page completed successfully. |
| RunOnceShown |
Not supported. Sets a registry value to indicate that the "first run" page has been shown. |
| 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. |
| SearchGuideUrl |
Not supported. Retrieves the URL of a page that can be used to install additional search providers. |
| SetActivitiesVisible |
Not supported. A setting that notifies the IShellUIHelper3::BuildNewTabPage method whether to show or hide the activities list. |
| 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. |
| SetRecentlyClosedVisible |
Not supported. A setting that notifies the IShellUIHelper3::BuildNewTabPage method whether to show or hide the list of recently closed tabs. |
| 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. |
| SkipRunOnce |
Not supported. Enables the user to select "first run" settings at a later time. |
| SkipTabsWelcome |
Not supported. Disables the welcome screen that appears when opening a new tab in Internet Explorer 7. |
| SqmEnabled |
Not supported. Determines whether SQM is enabled. |
| toStaticHTML |
Removes dynamic HTML elements and attributes from an HTML fragment. |
| webkitConvertPointFromNodeToPage |
Converts a point pt object from CSS node coordinates to page coordinates. |
| webkitConvertPointFromPageToNode |
Converts a point pt object from page coordinates to CSS node coordinates. |
Properties
The window object has these properties.
| Property | Access type | Description |
|---|---|---|
|
Returns a null value. | ||
|
Read-only |
Obsolete. Returns a timestamp of the start time of the current refresh interval, such that multiple animations can be synchronized with each other. | |
|
Read-only |
Returns an ApplicationCache object. | |
|
Retrieves whether the referenced window is closed. | ||
|
Read-only |
Returns the windows console object to use to send messages. | |
|
Returns a reference to the constructor of an object. | ||
|
Read-only |
Provides access to the the global Crypto object for performing cryptographic operations. | |
|
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. | ||
|
Read-only |
Returns whether a webpage is visible. | |
|
Read-only |
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. | ||
|
Read-only |
Returns true or false indicating whether or not the current context is secure. | |
|
Sets or retrieves the number of objects in a collection. | ||
|
Retrieves the Web Storage area specific to the current document. | ||
|
Read-only |
Used to determine if the location bar is visible to the user. | |
|
Retrieves the maximum number of concurrent connections to a Web server. | ||
|
Read-only |
Used to determine if the menu bar is visible to the user. | |
|
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. | ||
|
Read-only |
Returns a numeric value representing the orientation of the device. | |
|
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. | ||
|
Read-only |
Used to determine if the personal bar is visible to the user. | |
|
Sets or gets the value returned from the modal dialog window. This property is not supported for Windows 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. | ||
|
Read-only |
Used to determine if the scrollbars are visible to the user. | |
|
Read-only |
The distance the window was horizontally scrolled. | |
|
Read-only |
The distance the window was vertically scrolled. | |
|
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. | ||
|
Read-only |
Used to determine if the status bar is visible to the user. | |
|
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. | ||
|
Read-only |
Used to determine if the tool bar is visible to the user. | |
|
Retrieves the topmost ancestor window. | ||
| Instantiates the XMLHttpRequest object for the window. |
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.
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 apps using JavaScript
These window members are unavailable to Windows 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!');">
See also