Table of contents
- 1.1. Properties
- 1.2. Methods
- 1.3. Event Handlers
- 2. See also
This section provides a brief reference for all of the methods, properties, and events available through the DOM window object. The window object implements the Window interface, which in turn inherits from the AbstractView interface. Some additional global functions, namespaces objects, and constructors, not typically associated with the window, but available on it, are listed in the JavaScript Reference.
The window object represents the window itself. The document property of a window points to the DOM document loaded in that window. A window for a given document can be obtained using the
document.defaultView property.
In a tabbed browser, such as Firefox, each tab contains its own window object (and if you're writing an extension, the browser window itself is a separate window too - see Working with windows in chrome code for more information). That is, the window object is not shared between tabs in the same window. Some methods, namely
window.resizeTo and
window.resizeBy apply to the whole window and not to the specific tab the window object belongs to. Generally, anything that can't reasonably pertain to a tab pertains to the window instead.
Properties
-
window.applicationCacheRequires Gecko 1.9 - An
nsIDOMOfflineResourceListobject providing access to the offline resources for the window. -
window.closed - This property indicates whether the current window is closed or not.
- window.Components
- The entry point to many XPCOM features. Some properties, e.g. classes, are only available to sufficiently privileged code.
-
window.contentand window._content - Returns a reference to the content element in the current window. The variant with underscore is deprecated.
-
window.controllers - Returns the XUL controller objects for the current chrome window.
-
window.crypto - Returns the browser crypto object.
-
window.defaultStatus - Gets/sets the status bar text for the given window.
-
window.dialogArgumentsNew in Firefox 3 - Gets the arguments passed to the window (if it's a dialog box) at the time
was called. This is anwindow.showModalDialog()nsIArray. -
window.directoriesObsolete - Synonym of
window.personalbar -
window.document - Returns a reference to the document that the window contains.
-
window.frameElement - Returns the element in which the window is embedded, or null if the window is not embedded.
-
window.frames - Returns an array of the subframes in the current window.
-
window.fullScreenRequires Gecko 1.9 - This property indicates whether the window is displayed in full screen or not.
-
window.globalStorageRequires Gecko 1.8.1 Non-standard - Multiple storage objects that are used for storing data across multiple pages. Note that this is non-standard; it is recommended that you use window.localStorage instead.
-
window.history - Returns a reference to the history object.
-
window.innerHeight - Gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.
-
window.innerWidth - Gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.
-
window.length - Returns the number of frames in the window. See also
window.frames. -
window.location - Gets/sets the location, or current URL, of the window object.
-
window.locationbar - Returns the locationbar object, whose visibility can be toggled in the window.
- window.localStorage Requires Gecko 1.9.1
- Returns a reference to the local storage object used to store data that may only be accessed by the origin that created it.
-
window.menubar - Returns the menubar object, whose visibility can be toggled in the window.
-
window.messageManagerRequires Gecko 2.0 - Returns the message manager object for this window.
-
window.mozAnimationStartTimeRequires Gecko 2.0 - The time in milliseconds since epoch at which the current animation cycle began.
-
window.mozInnerScreenXRequires Gecko 1.9.2 - Returns the horizontal (X) coordinate of the top-left corner of the window's viewport, in screen coordinates. This value is reported in CSS pixels. See
mozScreenPixelsPerCSSPixelinnsIDOMWindowUtilsfor a conversion factor to adapt to screen pixels if needed. -
window.mozInnerScreenYRequires Gecko 1.9.2 - Returns the vertical (Y) coordinate of the top-left corner of the window's viewport, in screen coordinates. This value is reported in CSS pixels. See
mozScreenPixelsPerCSSPixelfor a conversion factor to adapt to screen pixels if needed. -
window.mozPaintCountRequires Gecko 2.0 - Returns the number of times the current document has been rendered to the screen in this window. This can be used to compute rendering performance.
-
window.name - Gets/sets the name of the window.
-
window.navigator - Returns a reference to the navigator object.
-
window.opener - Returns a reference to the window that opened this current window.
-
window.outerHeight - Gets the height of the outside of the browser window.
-
window.outerWidth - Gets the width of the outside of the browser window.
- window.pageXOffset
- An alias for
window.scrollX. - window.pageYOffset
- An alias for
window.scrollY -
window.parent - Returns a reference to the parent of the current window or subframe.
-
window.personalbar - Returns the personalbar object, whose visibility can be toggled in the window.
-
window.pkcs11Obsolete - Formerly provided access to install and remove PKCS11 modules. Now this property is always null.
-
window.returnValueNew in Firefox 3 - The return value to be returned to the function that called
to display the window as a modal dialog.window.showModalDialog() -
window.screen - Returns a reference to the screen object associated with the window.
-
window.screen.availTop - Specifies the y-coordinate of the first pixel that is not allocated to permanent or semipermanent user interface features.
-
window.screen.availLeft - Returns the first available pixel available from the left side of the screen.
-
window.screen.availHeight - Specifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.
-
window.screen.availWidth - Returns the amount of horizontal space in pixels available to the window.
-
window.screen.colorDepth - Returns the color depth of the screen.
-
window.screen.height - Returns the height of the screen in pixels.
-
window.screen.left - Returns the current distance in pixels from the left side of the screen.
-
window.screen.pixelDepth - Gets the bit depth of the screen.
-
window.screen.top - Returns the distance from the top of the screen.
-
window.screen.width - Returns the width of the screen.
-
window.screenX - Returns the horizontal distance of the left border of the user's browser from the left side of the screen.
-
window.screenY - Returns the vertical distance of the top border of the user's browser from the top side of the screen.
-
window.scrollbars - Returns the scrollbars object, whose visibility can be toggled in the window.
-
window.scrollMaxX - The maximum offset that the window can be scrolled to horizontally.
- (i.e., the document width minus the viewport width)
-
window.scrollMaxY - The maximum offset that the window can be scrolled to vertically (i.e., the document height minus the viewport height).
-
window.scrollX - Returns the number of pixels that the document has already been scrolled horizontally.
-
window.scrollY - Returns the number of pixels that the document has already been scrolled vertically.
-
window.self - Returns an object reference to the window object itself.
- window.sessionStorage New in Firefox 2.0
- A storage object for storing data within a single page session.
-
window.sidebar - Returns a reference to the window object of the sidebar.
-
window.status - Gets/sets the text in the statusbar at the bottom of the browser.
-
window.statusbar - Returns the statusbar object, whose visibility can be toggled in the window.
-
window.toolbar - Returns the toolbar object, whose visibility can be toggled in the window.
-
window.top - Returns a reference to the topmost window in the window hierarchy. This property is read only.
-
window.URLRequires Gecko 2.0 - A DOM URL object, which provides the
window.URL.createObjectURL()andwindow.URL.revokeObjectURL()methods. -
window.window - Returns a reference to the current window.
- window[0], window[1], etc.
- Returns a reference to the
windowobject in the frames. Seewindow.framesfor more details.
Methods
- window.addEventListener
- Register an event handler to a specific event type on the window.
-
window.alert - Displays an alert dialog.
-
window.atob - Decodes a string of data which has been encoded using base-64 encoding.
-
window.back - Moves back one in the window history.
-
window.blur - Sets focus away from the window.
-
window.btoa - Creates a base-64 encoded ASCII string from a string of binary data.
-
window.captureEventsObsolete - Registers the window to capture all events of the specified type.
-
window.clearImmediate - Cancels the repeated execution set using
setImmediate. -
window.clearInterval - Cancels the repeated execution set using
setInterval. -
window.clearTimeout - Cancels the repeated execution set using
setTimeout. -
window.close - Closes the current window.
-
window.confirm - Displays a dialog with a message that the user needs to respond to.
-
window.disableExternalCapture -
window.dispatchEvent -
window.dump - Writes a message to the console.
-
window.enableExternalCapture -
window.escape - Encodes a string.
-
window.find - Searches for a given string in a window.
-
window.focus - Sets focus on the current window.
-
window.forward - Moves the window one document forward in the history.
-
window.GeckoActiveXObject -
window.getAttention - Flashes the application icon.
-
window.getAttentionWithCycleCount -
window.getComputedStyle - Gets computed style for the specified element. Computed style indicates the computed values of all CSS properties of the element.
-
window.getSelection - Returns the selection object representing the selected item(s).
-
window.home - Returns the browser to the home page.
-
window.matchMediaRequires Gecko 6.0 - Returns a
MediaQueryListobject representing the specified media query string. -
window.maximize -
window.minimize(top-level XUL windows only) - Minimizes the window.
-
window.moveBy - Moves the current window by a specified amount.
-
window.moveTo - Moves the window to the specified coordinates.
-
window.mozRequestAnimationFrameRequires Gecko 2.0 - Tells the browser that an animation is in progress, requesting that the browser schedule a repaint of the window for the next animation frame. This will cause a
MozBeforePaintevent to fire before that repaint occurs. -
window.open - Opens a new window.
-
window.openDialog - Opens a new dialog window.
-
window.postMessageNew in Firefox 3 - Provides a secure means for one window to send a string of data to another window, which need not be within the same domain as the first, in a secure manner.
-
window.print - Opens the Print Dialog to print the current document.
-
window.prompt - Returns the text entered by the user in a prompt dialog.
-
window.QueryInterface -
window.releaseEventsObsolete - Releases the window from trapping events of a specific type.
- window.removeEventListener
- Removes an event listener from the window.
-
window.resizeBy - Resizes the current window by a certain amount.
-
window.resizeTo - Dynamically resizes window.
-
window.restore -
window.routeEventObsolete -
window.scroll - Scrolls the window to a particular place in the document.
-
window.scrollBy - Scrolls the document in the window by the given amount.
-
window.scrollByLines - Scrolls the document by the given number of lines.
-
window.scrollByPages - Scrolls the current document by the specified number of pages.
-
window.scrollTo - Scrolls to a particular set of coordinates in the document.
-
window.setCursor - Changes the cursor for the current window
-
window.setImmediate - Execute a function after the browser has finished other heavy tasks
-
window.setInterval - Execute a function each X milliseconds.
-
window.setResizable -
window.setTimeout - Sets a delay for executing a function.
-
window.showModalDialogNew in Firefox 3 - Displays a modal dialog.
-
window.sizeToContent - Sizes the window according to its content.
-
window.stop - This method stops window loading.
-
window.unescape - Unencodes a value that has been encoded in hexadecimal (e.g. a cookie).
-
window.updateCommands - Updates the state of commands of the current chrome window (UI).
- window.XPCNativeWrapper
-
window.XPCSafeJSObjectWrapper
Event Handlers
-
window.onabort - An event handler property for abort events on the window.
-
window.onbeforeunload - An event handler property for before-unload events on the window.
-
window.onblur - An event handler property for blur events on the window.
-
window.onchange - An event handler property for change events on the window.
-
window.onclick - An event handler property for click events on the window.
-
window.onclose - An event handler property for handling the window close event.
-
window.oncontextmenu - An event handler property for right-click events on the window.
-
window.ondevicemotionRequires Gecko 6.0 -
window.ondeviceorientationRequires Gecko 6.0 -
window.ondragdrop - An event handler property for drag and drop events on the window.
-
window.onerror - An event handler property for errors raised on the window.
-
window.onfocus - An event handler property for focus events on the window.
-
window.onhashchangeRequires Gecko 1.9.2 - An event handler property for hash change events on the window; called when the part of the URL after the hash mark ("#") changes.
-
window.onkeydown - An event handler property for keydown events on the window.
-
window.onkeypress - An event handler property for keypress events on the window.
-
window.onkeyup - An event handler property for keyup events on the window.
-
window.onload - An event handler property for window loading.
-
window.onmousedown - An event handler property for mousedown events on the window.
-
window.onmousemove - An event handler property for mousemove events on the window.
-
window.onmouseout - An event handler property for mouseout events on the window.
-
window.onmouseover - An event handler property for mouseover events on the window.
-
window.onmouseup - An event handler property for mouseup events on the window.
-
window.onmozbeforepaintRequires Gecko 2.0 - An event handler property for the
MozBeforePaintevent, which is sent before repainting the window if the event has been requested by a call to thewindow.mozRequestAnimationFrame()method. -
window.onpaint - An event handler property for paint events on the window.
-
window.onpopstateRequires Gecko 2.0 - An event handler property for popstate events, which are fired when navigating to a session history entry representing a state object.
-
window.onreset - An event handler property for reset events on the window.
-
window.onresize - An event handler property for window resizing.
-
window.onscroll - An event handler property for window scrolling.
-
window.onselect - An event handler property for window selection.
-
window.onsubmit - An event handler property for submits on window forms.
-
window.onunload - An event handler property for unload events on the window.
-
window.onpageshow - An event handler property for pageshow events on the window.
-
window.onpagehide - An event handler property for pagehide events on the window.

