Window - Web APIs | MDN
https://developer.mozilla.org/en-US/docs/Web/API/Window • 250 KB fetched
Open original page
Window - Web APIs | MDN
*
Skip to main content
*
Skip to search
HTML
HTML: Markup language
HTML reference
*
Elements
*
Global attributes
*
Attributes
*
See all…
HTML guides
*
Responsive images
*
HTML cheatsheet
*
Date & time formats
*
See all…
Markup languages
*
SVG
*
MathML
*
XML
CSS
CSS: Styling language
CSS reference
*
Properties
*
Selectors
*
At-rules
*
Values
*
See all…
CSS guides
*
Box model
*
Animations
*
Flexbox
*
Colors
*
See all…
Layout cookbook
*
Column layouts
*
Centering an element
*
Card component
*
See all…
JavaScript JS
JavaScript: Scripting language
JS reference
*
Standard built-in objects
*
Expressions & operators
*
Statements & declarations
*
Functions
*
See all…
JS guides
*
Control flow & error handing
*
Loops and iteration
*
Working with objects
*
Using classes
*
See all…
Web APIs
Web APIs: Programming interfaces
Web API reference
*
File system API
*
Fetch API
*
Geolocation API
*
HTML DOM API
*
Push API
*
Service worker API
*
See all…
Web API guides
*
Using the Web animation API
*
Using the Fetch API
*
Working with the History API
*
Using the Web speech API
*
Using web workers
All
All web technology
Technologies
*
Accessibility
*
HTTP
*
URI
*
Web extensions
*
WebAssembly
*
WebDriver
*
See all…
Topics
*
Media
*
Performance
*
Privacy
*
Security
*
Progressive web apps
Learn
Learn web development
Frontend developer course
*
Getting started modules
*
Core modules
*
MDN Curriculum
*
Check out the video course from Scrimba, our partner
Learn HTML
*
Structuring content with HTML module
Learn CSS
*
CSS styling basics module
*
CSS layout module
Learn JavaScript
*
Dynamic scripting with JavaScript module
Tools
Discover our tools
*
Playground
*
HTTP Observatory
*
Border-image generator
*
Border-radius generator
*
Box-shadow generator
*
Color format converter
*
Color mixer
*
Shape generator
About
Get to know MDN better
*
About MDN
*
Advertise with us
*
Community
*
MDN on GitHub
Blog
Toggle sidebar
*
Web
*
Web APIs
*
Window
Theme
*
OS default
*
Light
*
Dark
English (US)
Remember language
Learn more
*
Deutsch
*
English (US)
*
Español
*
Français
*
日本語
*
한국어
*
Português (do Brasil)
*
Русский
*
中文 (简体)
Window
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
*
See full compatibility
*
Learn more
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.
In this article
*
Instance properties
*
Instance methods
*
Events
*
Interfaces
*
Listening for events on Window
*
Specifications
*
Browser compatibility
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.crashReport Read only Secure context
Returns a CrashReportContext object that enables arbitrary data to be recorded for the current top-level browsing context, which is then added to a CrashReport and sent to a reporting endpoint when a browser crash occurs.
Window.credentialless Read only
Returns a boolean that indicates whether the current document was loaded inside a credentialless <iframe> . See 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 CustomElementRegistry object, which can be used to register new 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 Secure context
Returns a reference to the document Picture-in-Picture window for the current document context.
Window.fence Read only
Returns a Fence object instance for the current document context. Available only to documents embedded inside 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
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
When a progressive web app (PWA) is launched with a launch_handler client_mode value of focus-existing , navigate-new , or navigate-existing , the launchQueue provides access to the 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
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
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
Returns the current window 's associated Navigation object. The entry point for the 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
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 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 only
Returns the personalbar object.
Window.scheduler Read only
Returns the Scheduler object associated with the current context. This is the entry point for using the Prioritized Task Scheduling API .
Window.screen Read only
Returns a reference to the screen object associated with the window.
Window.screenX and Window.screenLeft Read only
Both properties return the horizontal distance from the left border of the user's browser window to the left side of the screen.
Window.screenY and Window.screenTop Read only
Both properties return the vertical distance from the top border of the user's browser window to the top side of the screen.
Window.scrollbars Read only
Returns the scrollbars object.
Window.scrollMaxX Read only
The maximum offset that the window can be scrolled to horizontally, that is the document width minus the viewport width.
Window.scrollMaxY 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 Secure context
Returns the WindowSharedStorage object for the current origin. This is the main entry point for writing data to shared storage using the Shared Storage API .
Window.speechSynthesis Read only
Returns a SpeechSynthesis object, which is the entry point into using 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 TrustedTypePolicyFactory object associated with the global object, providing the entry point for using the Trusted Types API .
Window.viewport Read only
Returns a Viewport object instance, which provides information about the current state of the device's viewport.
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.
Named properties
Some elements in the document are also exposed as window properties:
* For each <embed> , <form> , <iframe> , <img> , and <object> element, its name (if non-empty) is exposed.
For example, if the document contains <form name="my_form"> , then window["my_form"] (and its equivalent window.my_form ) returns a reference to that element.
* For each HTML element, its id (if non-empty) is exposed.
If a property corresponds to a single element, that element is directly returned. If the property corresponds to multiple elements, then an HTMLCollection is returned containing all of them. If any of the elements is a navigable <iframe> or <object> , then the contentWindow of first such iframe is returned instead.
Deprecated properties
Window.event 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 Read only
Returns an object with functions for adding external search providers to the browser.
Window.orientation Read only
Returns the orientation in degrees (in 90 degree increments) of the viewport relative to the device's natural orientation.
Window.status
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()
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 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.
Window.dump()
Writes a message to the console.
Window.fetch()
Starts the process of fetching a resource from the network.
Window.fetchLater()
Creates a deferred fetch, which is sent once the page is navigated away from (it is destroyed or enters the bfcache ), or after a provided activateAfter timeout — whichever comes first.
Window.find()
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()
Gets default computed style for the specified element, ignoring author stylesheets.
Window.getScreenDetails() Secure context
Returns a Promise that fulfills with 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() Secure context
Returns a Promise that fulfills with an array of 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.requestResize()
Updates the size information shared by an embedded document with its embedding parent, but only if the embedded document has opted in to sharing its size information.
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()
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.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() Secure context
Displays a directory picker which allows the user to select a directory.
Window.showOpenFilePicker() Secure context
Shows a file pi
Links found on this page
- Skip to main content [direct]
- HTML: Markup language [direct]
- Elements [direct]
- Global attributes [direct]
- Attributes [direct]
- See all… [direct]
- Responsive images [direct]
- HTML cheatsheet [direct]
- Date & time formats [direct]
- See all… [direct]
- SVG [direct]
- MathML [direct]
- XML [direct]
- CSS: Styling language [direct]
- Properties [direct]
- Selectors [direct]
- At-rules [direct]
- Values [direct]
- See all… [direct]
- Box model [direct]
- Animations [direct]
- Flexbox [direct]
- Colors [direct]
- See all… [direct]
- Column layouts [direct]
- Centering an element [direct]
- Card component [direct]
- See all… [direct]
- JavaScript: Scripting language [direct]
- Standard built-in objects [direct]
- Expressions & operators [direct]
- Statements & declarations [direct]
- Functions [direct]
- See all… [direct]
- Control flow & error handing [direct]
- Loops and iteration [direct]
- Working with objects [direct]
- Using classes [direct]
- See all… [direct]
- Web APIs: Programming interfaces [direct]
- File system API [direct]
- Fetch API [direct]
- Geolocation API [direct]
- HTML DOM API [direct]
- Push API [direct]
- Service worker API [direct]
- Using the Web animation API [direct]
- Using the Fetch API [direct]
- Working with the History API [direct]
- Using the Web speech API [direct]
- Using web workers [direct]
- All web technology [direct]
- Accessibility [direct]
- HTTP [direct]
- URI [direct]
- Web extensions [direct]
- WebAssembly [direct]
- WebDriver [direct]
- Media [direct]
- Performance [direct]
- Privacy [direct]
- Security [direct]
- Progressive web apps [direct]
- Learn web development [direct]
- Getting started modules [direct]
- Core modules [direct]
- MDN Curriculum [direct]
- Check out the video course from Scrimba, our partner [direct]
- Structuring content with HTML module [direct]
- CSS styling basics module [direct]
- CSS layout module [direct]
- Dynamic scripting with JavaScript module [direct]
- Playground [direct]
- HTTP Observatory [direct]
- Border-image generator [direct]
- Border-radius generator [direct]
- Box-shadow generator [direct]
- Color format converter [direct]
- Color mixer [direct]
- Shape generator [direct]