The Window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window. A window for a given document can be obtained using the
document.defaultView property. A global variable, window, representing the window in which the script is running, is exposed to JavaScript code. The Window interface is home to a variety of functions, namespaces, objects, and constructors which are not necessarily directly associated with the concept of a user interface window. However, the Window interface is a suitable place to include
these items that need to be globally available. Many of these are documented in the JavaScript Reference and the DOM Reference. In a tabbed browser, each tab is represented by its own Window object; the global window seen by JavaScript code running within a given tab always represents the tab
in which the code is running. That said, even in a tabbed browser, some properties and methods still apply to the overall window that contains the tab, such as resizeTo() and innerHeight. Generally, anything that can't reasonably pertain to a tab pertains to the window
instead.
Constructors
See also the DOM Interfaces.
DOMParserDOMParser can parse XML or HTML source stored in a string into a DOM Document. DOMParser is specified in DOM Parsing and Serialization.
HTMLImageElement.ImageUsed for creating an HTMLImageElement.
HTMLOptionElement.OptionUsed for creating an HTMLOptionElement.
StaticRange Experimental Read onlyReturns a StaticRange() constructor which creates a StaticRange object.
WorkerUsed for creating a Web worker.
XMLSerializerConverts a DOM tree into XML or HTML source.
Instance properties
This interface inherits properties from the EventTarget interface.
Note that properties which are objects (e.g., for overriding the prototype of built-in elements) are listed in a separate section below.
Window.clientInformation Read onlyAn alias for Window.navigator.
Window.closed Read onlyThis property indicates whether the current window is closed or not.
Window.console Read onlyReturns a reference to the console object which provides access to the browser's debugging console.
Window.customElements Read onlyReturns a reference to the CustomElementRegistry object, which can be used to register new custom elements and get information about previously registered custom elements.
Window.crypto Read onlyReturns the browser crypto object.
Window.devicePixelRatio Read onlyReturns the ratio between physical pixels and device independent pixels in the current display.
Window.document Read onlyReturns a reference to the document that the window contains.
Window.event Deprecated Read onlyReturns the current event, which is the event currently being handled by the JavaScript code's context, or undefined if no event is currently being handled. The Event object passed directly to event handlers should be used instead whenever possible.
Window.external Deprecated Read onlyReturns an object with functions for adding external search providers to the browser.
Window.frameElement Read onlyReturns the element in which the window is embedded, or null if the window is not embedded.
Window.frames Read onlyReturns an array of the subframes in the current window.
Window.fullScreen Non-standardThis property indicates whether the window is displayed in full screen or not.
Window.history Read onlyReturns a reference to the history object.
Window.innerHeight Read onlyGets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.
Window.innerWidth Read onlyGets the width of the content area of the browser window including, if rendered, the vertical scrollbar.
isSecureContext Experimental Read onlyReturns a boolean indicating whether the current context is secure (true) or not (false).
Window.length Read onlyReturns the number of frames in the window. See also window.frames.
Window.locationGets/sets the location, or current URL, of the window object.
Window.locationbar Read onlyReturns the locationbar object, whose visibility can be toggled in the window.
Window.localStorage Read onlyReturns a reference to the local storage object used to store data that may only be accessed by the origin that created it.
Returns the menubar object, whose visibility can be toggled in the window.
Window.messageManager Non-standardReturns the message manager object for this window.
Window.mozInnerScreenX Read only Non-standardReturns 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 mozScreenPixelsPerCSSPixel in nsIDOMWindowUtils for a conversion factor to adapt to screen pixels if needed.
Window.mozInnerScreenY Read only Non-standardReturns 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 mozScreenPixelsPerCSSPixel for a conversion factor to adapt to screen pixels if needed.
Window.nameGets/sets the name of the window.
Window.navigator Read onlyReturns a reference to the navigator object.
Window.openerReturns a reference to the window that opened this current window.
Window.outerHeight Read onlyGets the height of the outside of the browser window.
Window.outerWidth Read onlyGets the width of the outside of the browser window.
Window.pageXOffset Read onlyAn alias for window.scrollX.
Window.pageYOffset Read onlyAn alias for window.scrollY.
Window.parent Read onlyReturns a reference to the parent of the current window or subframe.
Window.performance Read onlyReturns a Performance object, which includes the timing and navigation attributes, each of which is an object providing performance-related data. See also Using Navigation Timing for additional information and examples.
Window.personalbar Read onlyReturns the personalbar object, whose visibility can be toggled in the window.
Window.screen Read onlyReturns a reference to the screen object associated with the window.
Window.screenX and Window.screenLeft Read onlyBoth properties return the horizontal distance from the left border of the user's browser viewport to the left side of the screen.
Window.screenY and Window.screenTop Read onlyBoth properties return the vertical distance from the top border of the user's browser viewport to the top side of the screen.
Returns the scrollbars object, whose visibility can be toggled in the window.
Window.scrollMaxX Non-standard Read onlyThe maximum offset that the window can be scrolled to horizontally, that is the document width minus the viewport width.
Window.scrollMaxY Non-standard Read onlyThe maximum offset that the window can be scrolled to vertically (i.e., the document height minus the viewport height).
Window.scrollX Read onlyReturns the number of pixels that the document has already been scrolled horizontally.
Window.scrollY Read onlyReturns the number of pixels that the document has already been scrolled vertically.
Window.self Read onlyReturns an object reference to the window object itself.
Window.sessionStorageReturns a reference to the session storage object used to store data that may only be accessed by the origin that created it.
Returns a reference to the window object of the sidebar.
Window.speechSynthesis Read onlyReturns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality.
Window.status DeprecatedGets/sets the text in the statusbar at the bottom of the browser.
Window.statusbar Read onlyReturns the statusbar object, whose visibility can be toggled in the window.
Window.toolbar Read onlyReturns the toolbar object, whose visibility can be toggled in the window.
Window.top Read onlyReturns a reference to the topmost window in the window hierarchy. This property is read only.
Window.visualViewport Read onlyReturns a VisualViewport object which represents the visual viewport for a given window.
Window.window Read onlyReturns a reference to the current window.
window[0], window[1], etc.Returns a reference to the window object in the frames. See Window.frames for more details.
Instance properties implemented from elsewhere
caches Read only
Returns the CacheStorage object associated with the current context. This object enables functionality such as storing assets for offline use, and generating custom responses to requests.
indexedDB Read onlyProvides a mechanism for applications to asynchronously access capabilities of indexed databases; returns an IDBFactory object.
origin Read onlyReturns the global object's origin, serialized as a string.
Window.scheduler Read onlyReturns the Scheduler object associated with the current context. This is the entry point for using the Prioritized Task Scheduling API.
Deprecated properties
Window.content and Window._content Non-standard Deprecated Read only
Returns a reference to the content element in the current window. Since Firefox 57 (initially Nightly-only), both versions are only available from chrome (privileged) code, and not available to the web anymore.
Window.defaultStatus DeprecatedGets/sets the status bar text for the given window.
Window.orientation Read only DeprecatedReturns the orientation in degrees (in 90 degree increments) of the viewport relative to the device's natural orientation.
Window.returnValue DeprecatedThe return value to be returned to the function that called window.showModalDialog() to display the window as a modal dialog.
Instance methods
This interface inherits methods from the EventTarget interface and implements methods from WindowOrWorkerGlobalScope and EventTarget.
Window.alert()Displays an alert dialog.
Window.blur()Sets focus away from the window.
Window.cancelAnimationFrame()Enables you to cancel a callback previously scheduled with Window.requestAnimationFrame.
Window.cancelIdleCallback()Enables you to cancel a callback previously scheduled with Window.requestIdleCallback.
Window.clearImmediate()Cancels the repeated execution set using setImmediate.
Window.close()Closes the current window.
Window.confirm()Displays a dialog with a message that the user needs to respond to.
Window.dump() Non-standardWrites a message to the console.
Window.find() Non-standardSearches for a given string in a window.
Window.focus()Sets focus on the current window.
Window.getComputedStyle()Gets computed style for the specified element. Computed style indicates the computed values of all CSS properties of the element.
Window.getDefaultComputedStyle() Non-standardGets default computed style for the specified element, ignoring author stylesheets.
Window.getSelection()Returns the selection object representing the selected item(s).
Window.matchMedia()Returns a MediaQueryList object representing the specified media query string.
Window.moveBy()Moves the current window by a specified amount.
Window.moveTo()Moves the window to the specified coordinates.
Window.open()Opens a new window.
Window.postMessage()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.
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.requestAnimationFrame()Tells the browser that an animation is in progress, requesting that the browser schedule a repaint of the window for the next animation frame.
Window.requestIdleCallback()Enables the scheduling of tasks during a browser's idle periods.
Window.resizeBy()Resizes the current window by a certain amount.
Window.resizeTo()Dynamically resizes window.
Window.scroll()Scrolls the window to a particular place in the document.
Scrolls the document in the window by the given amount.
Scrolls the document by the given number of lines.
Window.scrollByPages() Non-standardScrolls the current document by the specified number of pages.
Window.scrollTo()Scrolls to a particular set of coordinates in the document.
Window.setImmediate()Executes a function after the browser has finished other heavy tasks.
Window.setResizable() Non-standardToggles a user's ability to resize a window.
Window.sizeToContent() Non-standardSizes the window according to its content.
Window.showOpenFilePicker() ExperimentalShows a file picker that allows a user to select a file or multiple files.
Window.showSaveFilePicker() ExperimentalShows a file picker that allows a user to save a file.
Window.showDirectoryPicker() ExperimentalDisplays a directory picker which allows the user to select a directory.
Window.stop()This method stops window loading.
Window.updateCommands() Non-standardUpdates the state of commands of the current chrome window (UI).
Instance methods implemented from elsewhere
EventTarget.addEventListener()
Register an event handler to a specific event type on the window.
EventTarget.dispatchEvent()Used to trigger an event.
atob()Decodes a string of data which has been encoded using base-64 encoding.
btoa()Creates a base-64 encoded ASCII string from a string of binary data.
clearInterval()Cancels the repeated execution set using setInterval().
clearTimeout()Cancels the delayed execution set using setTimeout().
createImageBitmap()Accepts a variety of different image sources, and returns a Promise which resolves to an ImageBitmap. Optionally the source is cropped to the rectangle of pixels originating at (sx, sy) with width sw, and height sh.
fetch()Starts the process of fetching a resource from the network.
EventTarget.removeEventListener()Removes an event listener from the window.
setInterval()Schedules a function to execute every time a given number of milliseconds elapses.
setTimeout()Schedules a function to execute in a given amount of time.
reportError()Reports an error in a script, emulating an unhandled exception.
Deprecated methods
Window.back() Non-standard Deprecated
Moves back one in the window history. This method is deprecated; you should instead use window.history.back().
Window.captureEvents() DeprecatedRegisters the window to capture all events of the specified type.
Window.forward() Non-standard DeprecatedMoves the window one document forward in the history. This method is deprecated; you should instead use window.history.forward().
Window.home() Non-standard DeprecatedReturns the browser to the home page.
Window.openDialog() Non-standardOpens a new dialog window.
Window.releaseEvents() DeprecatedReleases the window from trapping events of a specific type.
Window.showModalDialog() Non-standard DeprecatedDisplays a modal dialog.
Events
Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.
errorFired when a resource failed to load, or can't be used. For example, if a script has an execution error or an image can't be found or is invalid.
languagechangeFired at the global scope object when the user's preferred language changes.
orientationchange DeprecatedFired when the orientation of the device has changed.
devicemotionFired at a regular interval, indicating the amount of physical force of acceleration the device is receiving and the rate of rotation, if available.
deviceorientationFired when fresh data is available from the magnetometer orientation sensor about the current orientation of the device as compared to the Earth coordinate frame.
resizeFired when the window has been resized.
storageFired when a storage area (localStorage or sessionStorage) has been modified in the context of another document.
vrdisplayconnect Deprecated Non-standardFired when a compatible VR device has been connected to the computer.
vrdisplaydisconnect Deprecated Non-standardFired when a compatible VR device has been disconnected from the computer.
vrdisplayactivate Deprecated Non-standardFired when a display is able to be presented to.
vrdisplaydeactivate Deprecated Non-standardFired when a display can no longer be presented to.
vrdisplayblur Deprecated Non-standardFired when presentation to a display has been paused for some reason by the browser, OS, or VR hardware.
vrdisplayfocus Deprecated Non-standardFired when presentation to a display has resumed after being blurred.
vrdisplaypresentchange Deprecated Non-standardFired when the presenting state of a VR device changes — i.e. goes from presenting to not presenting, or vice versa.
Animation events
animationcancel
Fired when an animation unexpectedly aborts.
animationendFired when an animation has completed normally.
animationiterationFired when an animation iteration has completed.
Fired when an animation starts.
Clipboard events
copy
Fired when the user initiates a copy action through the browser's user interface. Also available via the oncopy property.
cutFired when the user initiates a cut action through the browser's user interface. Also available via the oncut property.
pasteFired when the user initiates a paste action through the browser's user interface. Also available via the onpaste property.
Connection events
offline
Fired when the browser has lost access to the network and the value of navigator.onLine has switched to false.
onlineFired when the browser has gained access to the network and the value of navigator.onLine has switched to true.
Focus events
blur
Fired when an element has lost focus.
focusFired when an element has gained focus.
Gamepad events
gamepadconnected
Fired when the browser detects that a gamepad has been connected or the first time a button/axis of the gamepad is used.
gamepaddisconnectedFired when the browser detects that a gamepad has been disconnected.
History events
hashchange
Fired when the fragment identifier of the URL has changed (the part of the URL beginning with and following the # symbol).
pagehideSent when the browser hides the current document while in the process of switching to displaying in its place a different document from the session's history. This happens, for example, when the user clicks the Back button or when they click the Forward button to move ahead in session history.
pageshowSent when the browser makes the document visible due to navigation tasks, including not only when the page is first loaded, but also situations such as the user navigating back to the page after having navigated to another within the same tab.
popstateFired when the active history entry changes.
Load & unload events
beforeunload
Fired when the window, the document and its resources are about to be unloaded.
DOMContentLoadedFired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.
loadFired when the whole page has loaded, including all dependent resources such as stylesheets images.
unloadFired when the document or a child resource is being unloaded.
Manifest events
appinstalled
Fired when the browser has successfully installed a page as an application.
beforeinstallpromptFired when a user is about to be prompted to install a web application.
Messaging events
message
Fired when the window receives a message, for example from a call to Window.postMessage() from another browsing context.
messageerrorFired when a Window object receives a message that can't be deserialized.
Print events
afterprint
Fired after the associated document has started printing or the print preview has been closed.
beforeprintFired when the associated document is about to be printed or previewed for printing.
Promise rejection events
rejectionhandled
Sent every time a JavaScript Promise is rejected, regardless of whether or not there is a handler in place to catch the rejection.
unhandledrejectionSent when a JavaScript Promise is rejected but there is no handler in place to catch the rejection.
Transition events
transitioncancel
Fired when a CSS transition is canceled.
transitionendFired when a CSS transition has completed.
transitionrunFired when a CSS transition is first created.
transitionstartFired when a CSS transition has actually started.
WebVR events
vrdisplayactivate
Fired when a VR display becomes available to be presented to, for example if an HMD has been moved to bring it out of standby, or woken up by being put on. Also available via the onvrdisplayactivate property.
vrdisplayblurFired when presentation to a VR display has been paused for some reason by the browser, OS, or VR hardware. Also available via the onvrdisplayblur property.
vrdisplayconnectFired when a compatible VR display is connected to the computer. Also available via the onvrdisplayconnect property.
vrdisplaydeactivateFired when a VR display can no longer be presented to, for example if an HMD has gone into standby or sleep mode due to a period of inactivity. Also available via the onvrdisplaydeactivate property.
vrdisplaydisconnectFired when a compatible VR display is disconnected from the computer. Also available via the onvrdisplaydisconnect property.
vrdisplayfocusFired when presentation to a VR display has resumed after being blurred. Also available via the onvrdisplayfocus property.
vrdisplaypresentchangeFired when the presenting state of a VR display changes — i.e. goes from presenting to not presenting, or vice versa. Also available via the onvrdisplaypresentchange property.
vrdisplaypointerrestricted Deprecated Non-standardFired when the VR display's pointer input is restricted to consumption via a pointerlocked element. Also available via the onvrdisplaypointerrestricted property.
vrdisplaypointerunrestricted Deprecated Non-standardFired when the VR display's pointer input is no longer restricted to consumption via a pointerlocked element. Also available via the onvrdisplaypointerunrestricted property.
Interfaces
Specifications
HTML Standard # the-window-object |
Browser compatibility
BCD tables only load in the browser