This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



The window object is the top level Javascript object in a page, and is the global scope for a browser tab. Global Javascript variables appear in the window object, as well as several important objects such as Document.

Inherits from EventTargetEventTarget


Sets or gets the URL for the current document.
Represents an XML request using HTTP.
Obsolete. Returns a timestamp of the start time of the current refresh interval, such that multiple animations can be synchronized with each other.
This read-only property indicates whether the referenced window is closed or not.
Sets or retrieves the default message displayed in the status bar at the bottom of the window.
Returns the window itself, which is an array-like object, listing the direct sub-frames of the current window.
Provides access to the IndexedDB features supported by the browser and/or device.
Height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.


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 the text in the status bar at the bottom of the browser or returns the previously set text.
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.


Displays a synchronized dialog box showing the given text and a localized OK button.
Cancels a requestAnimationFrame request
Cancels a function request created with setImmediate.
Cancels the interval previously started using the setInterval method.
Cancels a time-out that was set with the setTimeout method.
Closes the current browser window or tab, or HTML Application (HTA).
Displays a synchronized confirmation dialog box showing the given text and possibly localized OK and Cancel buttons.
Gets the values of all the CSS properties of an element after applying the active stylesheets and resolving the basic computations they may contain. The returned object is of the same type that the object returned from the element’s “style” property, however the two objects have different purposes. The object returned from getComputedStyle is read-only and can be used to inspect the element’s style (including those set by a <style> element or an external stylesheet). The object should be used to set styles on a specific element.
Returns a Selection object that represents the current selection of the document.
Moves the screen position of the window by the specified x and y offset values.
Moves a table row to a new position.
Moves the screen position of the upper-left corner of the window to the specified x and y position
Opens a new window and loads the document specified by a given URL.
Sends a cross-document message.
A method to invoke at the optimal time a callback to update the frame of an animation.
Changes the current size of the window by the specified x- and y-offset.
Sets the size of the window to the specified width and height values.
Causes the window to scroll to the specified x- and y-offset at the upper-left corner of the window.
Causes the window to scroll relative to the current scrolled position by the specified x- and y-pixel offset.
Scrolls the window to the specified x- and y-offset.
Requests that a function be called when current or pending tasks are complete, such as events or screen updates.
Evaluates an expression each time a specified number of milliseconds has elapsed.
Evaluates an expression after a specified number of milliseconds has elapsed.
Do not use. Use <dialog> or a popup window instead. Halts the script execution, creates a popup window, passes it parameters and returns a value when the new window is closed.


Fires when a message is received from another context (frame, window, worker and similar).

Inherited from EventTarget


No properties.


Registers an event handler for the specified event type.
Sends an event to the current element.
Removes an event handler that the addEventListener method registered.


No events.


This example displays an alert for the current window.

alert("A simple message.")
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!');">


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.

openeropenThe opener property is available only from a document opened using the method.
parent, topNoneThe 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, topopenThe parent and top properties are available for a window opened via the open method or as a dialog and returns the current window.
lengthNoneRegardless of how the window is opened, the length property returns the number of frames in a window.
dialogArguments, dialogHeight, dialogLeft, dialogTop, dialogWidth, returnValueshowModalDialog and showModelessDialogThese 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.