• Web APIs
  • caches
  • credentialless Experimental
  • devicePixelRatio
  • documentPictureInPicture Experimental
  • event Deprecated
  • external Deprecated
  • fence Experimental
  • fullScreen Non-standard
  • innerWidth
  • launchQueue Experimental
  • locationbar
  • mozInnerScreenX Non-standard
  • mozInnerScreenY Non-standard
  • navigation Experimental
  • orientation Deprecated
  • originAgentCluster Experimental
  • performance
  • screenLeft
  • scrollbars
  • scrollMaxX Non-standard
  • scrollMaxY Non-standard
  • sessionStorage
  • sharedStorage Experimental
  • status Deprecated
  • trustedTypes
  • atob()
  • back() Non-standard Deprecated
  • blur() Deprecated
  • captureEvents() Deprecated
  • clearImmediate() Non-standard Deprecated
  • confirm()
  • dump() Non-standard
  • find() Non-standard
  • forward() Non-standard Deprecated
  • getDefaultComputedStyle() Non-standard
  • getScreenDetails() Experimental
  • moveTo()
  • prompt()
  • queryLocalFonts() Experimental
  • releaseEvents() Deprecated
  • requestFileSystem() Non-standard Deprecated
  • scroll()
  • scrollByLines() Non-standard
  • scrollByPages() Non-standard
  • setImmediate() Non-standard Deprecated
  • setResizable() Non-standard Deprecated
  • showDirectoryPicker() Experimental
  • showModalDialog() Non-standard Deprecated
  • showOpenFilePicker() Experimental
  • showSaveFilePicker() Experimental
  • sizeToContent() Non-standard
  • webkitConvertPointFromNodeToPage() Non-standard Deprecated
  • webkitConvertPointFromPageToNode() Non-standard Deprecated
  • Events
    1. beforeprint
    2. cut
    3. error
    4. hashchange
    5. messageerror
    6. orientationchange Deprecated
    7. pageswap
    8. resize
    9. scrollsnapchange Experimental
    10. scrollsnapchanging Experimental
    11. unload Deprecated
    12. vrdisplayactivate Non-standard Deprecated
    13. vrdisplayconnect Non-standard Deprecated
    14. vrdisplaydeactivate Non-standard Deprecated
    15. vrdisplaydisconnect Non-standard Deprecated
    16. vrdisplaypresentchange Non-standard Deprecated
  • Inheritance
    1. AbstractRange
    2. Comment
    3. DOMError Deprecated
    4. DOMPoint
    5. Document
    6. Event
    7. MutationRecord
    8. NodeList
    9. Text
    10. TreeWalker
    11. 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 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 innerHeight. Generally, anything that can't reasonably pertain to a tab pertains to the window instead.

      EventTarget Window
  • 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.caches Read only Secure context

    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.

    Window.clientInformation Read only

    An alias for Window.navigator.

    Window.closed Read only

    This property indicates whether the current window is closed or not.

    Window.cookieStore Read only Secure context

    Returns a reference to the CookieStore object for the current document context.

    Window.credentialless Read only Experimental

    Returns a boolean that indicates whether the current document was loaded inside a credentialless IFrame credentialless for more details.

    Window.crossOriginIsolated Read only

    Returns a boolean value that indicates whether the website is in a cross-origin isolation state.

    Window.crypto Read only

    Returns the Crypto object associated to the global object.

    Window.customElements Read only

    Returns a reference to the custom elements and get information about previously registered custom elements.

    Window.devicePixelRatio Read only

    Returns the ratio between physical pixels and device independent pixels in the current display.

    Window.document Read only

    Returns a reference to the document that the window contains.

    Window.documentPictureInPicture Read only Experimental Secure context

    Returns a reference to the document Picture-in-Picture window for the current document context.

    Window.fence Read only Experimental

    Returns a <fencedframe>.

    Window.frameElement Read only

    Returns the element in which the window is embedded, or null if the window is not embedded.

    Window.frames Read only

    Returns an array of the subframes in the current window.

    Window.fullScreen Non-standard

    This property indicates whether the window is displayed in full screen or not.

    Window.history Read only

    Returns a reference to the history object.

    Window.indexedDB Read only

    Provides a mechanism for applications to asynchronously access capabilities of indexed databases; returns an IDBFactory object.

    Window.innerHeight Read only

    Gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.

    Window.innerWidth Read only

    Gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.

    Window.isSecureContext Read only

    Returns a boolean indicating whether the current context is secure (true) or not (false).

    Window.launchQueue Read only Experimental

    When a LaunchQueue class, which allows custom launch navigation handling to be implemented for the PWA.

    Window.length Read only

    Returns the number of frames in the window. See also window.frames.

    Window.localStorage Read only

    Returns a reference to the local storage object used to store data that may only be accessed by the origin that created it.

    Window.location

    Gets/sets the location, or current URL, of the window object.

    Window.locationbar Read only

    Returns the locationbar object.

    Window.menubar Read only

    Returns the menubar object.

    Window.mozInnerScreenX Read only Non-standard

    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 mozScreenPixelsPerCSSPixel in nsIDOMWindowUtils for a conversion factor to adapt to screen pixels if needed.

    Window.mozInnerScreenY Read only Non-standard

    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 mozScreenPixelsPerCSSPixel for a conversion factor to adapt to screen pixels if needed.

    Window.name

    Gets/sets the name of the window.

    Window.navigation Read only Experimental

    Returns the current window's associated Navigation API.

    Window.navigator Read only

    Returns a reference to the navigator object.

    Window.opener

    Returns a reference to the window that opened this current window.

    Window.origin Read only

    Returns the global object's origin, serialized as a string.

    Window.originAgentCluster Read only Experimental

    Returns true if this window belongs to an origin-keyed agent cluster.

    Window.outerHeight Read only

    Gets the height of the outside of the browser window.

    Window.outerWidth Read only

    Gets the width of the outside of the browser window.

    Window.pageXOffset Read only

    An alias for window.scrollX.

    Window.pageYOffset Read only

    An alias for window.scrollY.

    Window.parent Read only

    Returns a reference to the parent of the current window or subframe.

    Window.performance Read only

    Returns a performance-related data. See also Using Navigation Timing for additional information and examples.

    Window.personalbar Read only

    Returns the personalbar object.

    Window.scheduler Read only

    Returns the Prioritized Task Scheduling API.

    Window.screen Read only

    Returns a reference to the screen object associated with the window.

    Window.screenLeft Read only

    Both properties return the horizontal distance from the left border of the user's browser viewport to the left side of the screen.

    Window.screenTop Read only

    Both properties return the vertical distance from the top border of the user's browser viewport to the top side of the screen.

    Window.scrollbars Read only

    Returns the scrollbars object.

    Window.scrollMaxX Non-standard Read only

    The maximum offset that the window can be scrolled to horizontally, that is the document width minus the viewport width.

    Window.scrollMaxY Non-standard Read only

    The maximum offset that the window can be scrolled to vertically (i.e., the document height minus the viewport height).

    Window.scrollX Read only

    Returns the number of pixels that the document has already been scrolled horizontally.

    Window.scrollY Read only

    Returns the number of pixels that the document has already been scrolled vertically.

    Window.self Read only

    Returns an object reference to the window object itself.

    Window.sessionStorage

    Returns a reference to the session storage object used to store data that may only be accessed by the origin that created it.

    Window.sharedStorage Read only Experimental Secure context

    Returns the Shared Storage API.

    Window.speechSynthesis Read only

    Returns a Web Speech API speech synthesis functionality.

    Window.statusbar Read only

    Returns the statusbar object.

    Window.toolbar Read only

    Returns the toolbar object.

    Window.top Read only

    Returns a reference to the topmost window in the window hierarchy. This property is read only.

    Window.trustedTypes Read only

    Returns the Trusted Types API.

    Window.visualViewport Read only

    Returns a VisualViewport object which represents the visual viewport for a given window.

    Window.window Read only

    Returns 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.

    Deprecated properties

    Window.event Deprecated Read only

    Returns 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 only

    Returns an object with functions for adding external search providers to the browser.

    Window.orientation Deprecated Read only

    Returns the orientation in degrees (in 90 degree increments) of the viewport relative to the device's natural orientation.

    Window.status Deprecated

    Gets/sets the text in the statusbar at the bottom of the browser.

    Instance methods

    This interface inherits methods from the EventTarget interface.

    Window.atob()

    Decodes a string of data which has been encoded using base-64 encoding.

    Window.alert()

    Displays an alert dialog.

    Window.blur() Deprecated

    Sets focus away from the window.

    Window.btoa()

    Creates a base-64 encoded ASCII string from a string of binary data.

    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.clearInterval()

    Cancels the repeated execution set using Window.setInterval().

    Window.clearTimeout()

    Cancels the delayed execution set using Window.setTimeout().

    Window.close()

    Closes the current window.

    Window.confirm()

    Displays a dialog with a message that the user needs to respond to.

    Window.createImageBitmap()

    Accepts a variety of different image sources, and returns a ImageBitmap. Optionally the source is cropped to the rectangle of pixels originating at (sx, sy) with width sw, and height sh.

    Window.dump() Non-standard

    Writes a message to the console.

    Window.fetch()

    Starts the process of fetching a resource from the network.

    Window.find() Non-standard

    Searches 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-standard

    Gets default computed style for the specified element, ignoring author stylesheets.

    Window.getScreenDetails() Experimental Secure context

    Returns a ScreenDetails object instance representing the details of all the screens available to the user's device.

    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.queryLocalFonts() Experimental Secure context

    Returns a FontData objects representing the font faces available locally.

    Window.queueMicrotask()

    Queues a microtask to be executed at a safe time prior to control returning to the browser's event loop.

    Window.reportError()

    Reports an error in a script, emulating an unhandled exception.

    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.

    Window.scrollBy()

    Scrolls the document in the window by the given amount.

    Window.scrollByLines() Non-standard

    Scrolls the document by the given number of lines.

    Window.scrollByPages() Non-standard

    Scrolls the current document by the specified number of pages.

    Window.scrollTo()

    Scrolls to a particular set of coordinates in the document.

    Window.setInterval()

    Schedules a function to execute every time a given number of milliseconds elapses.

    Window.setTimeout()

    Schedules a function to execute in a given amount of time.

    Window.showDirectoryPicker() Experimental Secure context

    Displays a directory picker which allows the user to select a directory.

    Window.showOpenFilePicker() Experimental Secure context

    Shows a file picker that allows a user to select a file or multiple files.

    Window.showSaveFilePicker() Experimental Secure context

    Shows a file picker that allows a user to save a file.

    Window.sizeToContent() Non-standard

    Sizes the window according to its content.

    Window.stop()

    This method stops window loading.

    Window.structuredClone()

    Creates a structured clone algorithm.

    Deprecated methods

    Window.back() Non-standard Deprecated

    Moves back one in the window history. This method is deprecated; you should instead use history.back().

    Window.captureEvents() Deprecated

    Registers the window to capture all events of the specified type.

    Window.clearImmediate() Non-standard Deprecated

    Cancels the repeated execution set using setImmediate().

    Window.forward() Non-standard Deprecated

    Moves the window one document forward in the history. This method is deprecated; you should instead use history.forward().

    Window.releaseEvents() Deprecated

    Releases the window from trapping events of a specific type.

    Window.requestFileSystem() Non-standard Deprecated

    Lets a website or app gain access to a sandboxed file system for its own use.

    Window.setImmediate() Non-standard Deprecated

    Executes a function after the browser has finished other heavy tasks.

    Window.setResizable() Non-standard Deprecated

    Does nothing (no-op). Kept for backward compatibility with Netscape 4.x.

    Window.showModalDialog() Non-standard Deprecated

    Displays a modal dialog.

    Window.webkitConvertPointFromNodeToPage() Non-standard Deprecated

    Transforms a WebKitPoint from the node's coordinate system to the page's coordinate system.

    Window.webkitConvertPointFromPageToNode() Non-standard Deprecated

    Transforms a WebKitPoint from the page's coordinate system to the node's coordinate system.

    Events

    Listen to these events using Document contained in the window object.

    error

    Fired 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.

    languagechange

    Fired at the global scope object when the user's preferred language changes.

    resize

    Fired when the window has been resized.

    storage

    Fired when a storage area (localStorage or sessionStorage) has been modified in the context of another document.

    Clipboard events

    copy

    Fired when the user initiates a copy action through the browser's user interface. Also available via the oncopy property.

    cut

    Fired when the user initiates a cut action through the browser's user interface. Also available via the oncut property.

    paste

    Fired 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.

    online

    Fired when the browser has gained access to the network and the value of navigator.onLine has switched to true.

    Device orientation events

    devicemotion Secure context

    Fired at a regular interval, indicating the amount of physical force of acceleration the device is receiving and the rate of rotation, if available.

    deviceorientation Secure context

    Fired when fresh data is available from the magnetometer orientation sensor about the current orientation of the device as compared to the Earth coordinate frame.

    deviceorientationabsolute Secure context

    Fired when fresh data is available from the magnetometer orientation sensor about the current absolute orientation of the device as compared to the Earth coordinate frame.

    Focus events

    blur

    Fired when an element has lost focus.

    focus

    Fired 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.

    gamepaddisconnected

    Fired 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).

    pagehide

    Sent 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.

    pagereveal

    Fired when a document is first rendered, either when loading a fresh document from the network or activating a document (either from prerender).

    pageshow

    Sent 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.

    pageswap

    Fired when a document is about to be unloaded due to a navigation.

    popstate

    Fired when the active history entry changes.

    Load & unload events

    beforeunload

    Fired when the window, the document and its resources are about to be unloaded.

    load

    Fired when the whole page has loaded, including all dependent resources such as stylesheets images.

    unload Deprecated

    Fired 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.

    beforeinstallprompt

    Fired 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.

    messageerror

    Fired when a Window object receives a message that can't be deserialized.

    afterprint

    Fired after the associated document has started printing or the print preview has been closed.

    beforeprint

    Fired 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.

    unhandledrejection

    Sent when a JavaScript Promise is rejected but there is no handler in place to catch the rejection.

    Scroll events

    scrollsnapchange Experimental

    Fired on the scroll container at the end of a scrolling operation when a new scroll snap target has been selected.

    scrollsnapchanging Experimental

    Fired on the scroll container when the browser determines a new scroll snap target is pending, i.e. it will be selected when the current scroll gesture ends.

    Deprecated events

    orientationchange Deprecated

    Fired when the orientation of the device has changed.

    vrdisplayactivate Deprecated Non-standard

    Fired when a display is able to be presented to.

    vrdisplayconnect Deprecated Non-standard

    Fired when a compatible VR device has been connected to the computer.

    vrdisplaydisconnect Deprecated Non-standard

    Fired when a compatible VR device has been disconnected from the computer.

    vrdisplaydeactivate Deprecated Non-standard

    Fired when a display can no longer be presented to.

    vrdisplaypresentchange Deprecated Non-standard

    Fired when the presenting state of a VR device changes — i.e. goes from presenting to not presenting, or vice versa.

    Bubbled events

    Interfaces

    Listening for events on Window

    HTML elements have three ways to listen for events:

    • Add an event listener to the element using the EventTarget.addEventListener method.
    • Assign an event handler to the element's oneventname property in JavaScript.
    • Add an on-prefixed attribute to the element in the HTML.

    To listen for events on Window objects, in general, you can only use the first two methods, because Window has no corresponding HTML element. However, there's a specific group of events whose listeners can be added to the <frameset>) element that's owned by the Window's document, using the second or third methods. These events are:

    • afterprint
    • beforeprint
    • beforeunload
    • blur
    • error
    • focus
    • hashchange
    • languagechange
    • load
    • message
    • messageerror
    • offline
    • online
    • pagehide
    • pagereveal
    • pageshow
    • pageswap
    • popstate
    • rejectionhandled
    • resize
    • scroll
    • storage
    • unhandledrejection
    • unload

    This means the following are strictly equivalent:

    js
    window.onresize = (e) => console.log(e.currentTarget);
    document.body.onresize = (e) => console.log(e.currentTarget);
    
    html
    <body onresize="console.log(event.currentTarget)"></body>
    

    In all three cases, you see the Window object logged as currentTarget.

    Specifications

    Specification
    Product help\n
  • canplaythrough
  • \n
  • contextlost
  • \n
  • cuechange
  • \n
  • dragend
  • \n
  • dragstart
  • \n
  • ended
  • \n
  • keydown
  • \n
  • loadedmetadata
  • \n
  • mouseleave
  • \n
  • mouseup
  • \n
  • playing
  • \n
  • scrollend
  • \n
  • select
  • \n
  • suspend
  • \n
  • waiting
  • \n
  • <body> (or the deprecated caches
  • crossOriginIsolated
  • document
  • fence\nExperimental\n
  • history
  • isSecureContext
  • location
  • mozInnerScreenY\nNon-standard\n
  • opener
  • outerHeight
  • personalbar
  • screenTop
  • scrollMaxX\nNon-standard\n
  • self
  • status\nDeprecated\n
  • trustedTypes
  • atob()
  • cancelAnimationFrame()
  • clearInterval()
  • createImageBitmap()
  • focus()
  • getScreenDetails()\nExperimental\n
  • moveTo()
  • prompt()
  • reportError()
  • resizeBy()
  • scrollByLines()\nNon-standard\n
  • setInterval()
  • showModalDialog()\nNon-standard\n\nDeprecated\n
  • stop()
  • afterprint
  • beforeunload
  • devicemotion
  • focus
  • languagechange
  • offline
  • pagereveal
  • popstate
  • scrollsnapchanging\nExperimental\n
  • vrdisplayactivate\nNon-standard\n\nDeprecated\n
  • vrdisplaypresentchange\nNon-standard\n\nDeprecated\n
  • Inheritance
    1. AbstractRange
    2. Comment
    3. DOMImplementation
    4. DOMRect
    5. DocumentType
    6. HTMLCollection
    7. Node
    8. Range
    9. TextEncoder
    10. XMLDocument
  • ","source":{"folder":"en-us/web/api/window","github_url":"https://github.com/mdn/content/blob/main/files/en-us/web/api/window/index.md","last_commit_url":"https://github.com/mdn/content/commit/05187b0fecf39b9176d4a101623589309cf44dd0","filename":"index.md"},"summary":"The Window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window.","title":"Window","toc":[{"text":"Instance properties","id":"instance_properties"},{"text":"Instance methods","id":"instance_methods"},{"text":"Events","id":"events"},{"text":"Interfaces","id":"interfaces"},{"text":"Listening for events on Window","id":"listening_for_events_on_window"},{"text":"Specifications","id":"specifications"},{"text":"Browser compatibility","id":"browser_compatibility"}],"baseline":{"baseline":"high","baseline_low_date":"2015-07-29","baseline_high_date":"2018-01-29","support":{"chrome":"1","chrome_android":"18","edge":"12","firefox":"1","firefox_android":"4","safari":"1","safari_ios":"1"},"asterisk":true},"browserCompat":["api.Window"],"pageType":"web-api-interface"}}

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant