Window extension type

The Window interface represents a window containing a 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 Window.resizeTo and Window.innerHeight. Generally, anything that can't reasonably pertain to a tab pertains to the window instead.


API documentation sourced from MDN Web Docs.

on
Implemented types
Available extensions

Properties

caches CacheStorage
The caches read-only property of the Window interface 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.
no setter
closed bool
The Window.closed read-only property indicates whether the referenced window is closed or not.
no setter
crossOriginIsolated bool
The crossOriginIsolated read-only property of the Window interface returns a boolean value that indicates whether the website is in a cross-origin isolation state. That state mitigates the risk of side-channel attacks and unlocks a few capabilities:
no setter
crypto Crypto
The crypto read-only property of the Window interface returns the Crypto object for this window's scope. This object gives web pages access to certain cryptographic related services.
no setter
customElements CustomElementRegistry
The customElements read-only property of the Window interface returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and get information about previously registered custom elements.
no setter
devicePixelRatio double
The devicePixelRatio of Window interface returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
no setter
document Document
window.document returns a reference to the document contained in the window.
no setter
event Event?
The read-only Window property event returns the Event which is currently being handled by the site's code. Outside the context of an event handler, the value is always undefined.
no setter
external External
The external property of the Window API returns an instance of the External interface, which was intended to contain functions related to adding external search providers to the browser. However, this is now deprecated, and the contained methods are now dummy functions that do nothing as per spec.
no setter
frameElement Element?
The Window.frameElement property returns the element (such as iframe or object) in which the window is embedded.
no setter
frames Window
Returns the window itself, which is an array-like object, listing the direct sub-frames of the current window.
no setter
hashCode int
The hash code for this object.
no setterinherited
history History
The Window.history read-only property returns a reference to the History object, which provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in).
no setter
indexedDB IDBFactory
The indexedDB read-only property of the Window interface provides a mechanism for applications to asynchronously access the capabilities of indexed databases.
no setter
innerHeight int
The read-only innerHeight property of the Window interface returns the interior height of the window in pixels, including the height of the horizontal scroll bar, if present.
no setter
innerWidth int
The read-only Window property innerWidth returns the interior width of the window in pixels (that is, the width of the window's ). That includes the width of the vertical scroll bar, if one is present.
no setter
isSecureContext bool
The isSecureContext read-only property of the Window interface returns a boolean indicating whether the current context is secure (true) or not (false).
no setter
length int
Returns the number of frames (either frame or iframe elements) in the window.
no setter
localStorage Storage
The localStorage read-only property of the window interface allows you to access a Storage object for the Document's ; the stored data is saved across browser sessions.
no setter
location Location
The Window.location read-only property returns a Location object with information about the current location of the document.
no setter
locationbar BarProp
Returns the locationbar object.
no setter
Returns the menubar object.
no setter
name String
The Window.name property gets/sets the name of the window's browsing context.
getter/setter pair
The Window.navigator read-only property returns a reference to the Navigator object, which has methods and properties about the application running the script.
no setter
onabort EventHandler?
getter/setter pair
onafterprint EventHandler?
getter/setter pair
onanimationcancel EventHandler?
getter/setter pair
onanimationend EventHandler?
getter/setter pair
onanimationiteration EventHandler?
getter/setter pair
onanimationstart EventHandler?
getter/setter pair
onappinstalled EventHandler?
getter/setter pair
onauxclick EventHandler?
getter/setter pair
onbeforeinput EventHandler?
getter/setter pair
onbeforeinstallprompt EventHandler?
getter/setter pair
onbeforeprint EventHandler?
getter/setter pair
onbeforetoggle EventHandler?
getter/setter pair
onbeforeunload OnBeforeUnloadEventHandler?
getter/setter pair
onblur EventHandler?
getter/setter pair
oncancel EventHandler?
getter/setter pair
oncanplay EventHandler?
getter/setter pair
oncanplaythrough EventHandler?
getter/setter pair
onchange EventHandler?
getter/setter pair
onclick EventHandler?
getter/setter pair
onclose EventHandler?
getter/setter pair
oncontextlost EventHandler?
getter/setter pair
oncontextmenu EventHandler?
getter/setter pair
oncontextrestored EventHandler?
getter/setter pair
oncopy EventHandler?
getter/setter pair
oncuechange EventHandler?
getter/setter pair
oncut EventHandler?
getter/setter pair
ondblclick EventHandler?
getter/setter pair
ondevicemotion EventHandler?
getter/setter pair
ondeviceorientation EventHandler?
getter/setter pair
ondeviceorientationabsolute EventHandler?
getter/setter pair
ondrag EventHandler?
getter/setter pair
ondragend EventHandler?
getter/setter pair
ondragenter EventHandler?
getter/setter pair
ondragleave EventHandler?
getter/setter pair
ondragover EventHandler?
getter/setter pair
ondragstart EventHandler?
getter/setter pair
ondrop EventHandler?
getter/setter pair
ondurationchange EventHandler?
getter/setter pair
onemptied EventHandler?
getter/setter pair
onended EventHandler?
getter/setter pair
onerror OnErrorEventHandler?
getter/setter pair
onfocus EventHandler?
getter/setter pair
onformdata EventHandler?
getter/setter pair
ongamepadconnected EventHandler?
getter/setter pair
ongamepaddisconnected EventHandler?
getter/setter pair
ongotpointercapture EventHandler?
getter/setter pair
onhashchange EventHandler?
getter/setter pair
oninput EventHandler?
getter/setter pair
oninvalid EventHandler?
getter/setter pair
onkeydown EventHandler?
getter/setter pair
onkeypress EventHandler?
getter/setter pair
onkeyup EventHandler?
getter/setter pair
onlanguagechange EventHandler?
getter/setter pair
onload EventHandler?
getter/setter pair
onloadeddata EventHandler?
getter/setter pair
onloadedmetadata EventHandler?
getter/setter pair
onloadstart EventHandler?
getter/setter pair
onlostpointercapture EventHandler?
getter/setter pair
onmessage EventHandler?
getter/setter pair
onmessageerror EventHandler?
getter/setter pair
onmousedown EventHandler?
getter/setter pair
onmouseenter EventHandler?
getter/setter pair
onmouseleave EventHandler?
getter/setter pair
onmousemove EventHandler?
getter/setter pair
onmouseout EventHandler?
getter/setter pair
onmouseover EventHandler?
getter/setter pair
onmouseup EventHandler?
getter/setter pair
onoffline EventHandler?
getter/setter pair
ononline EventHandler?
getter/setter pair
onorientationchange EventHandler?
getter/setter pair
onpagehide EventHandler?
getter/setter pair
onpageshow EventHandler?
getter/setter pair
onpaste EventHandler?
getter/setter pair
onpause EventHandler?
getter/setter pair
onplay EventHandler?
getter/setter pair
onplaying EventHandler?
getter/setter pair
onpointercancel EventHandler?
getter/setter pair
onpointerdown EventHandler?
getter/setter pair
onpointerenter EventHandler?
getter/setter pair
onpointerleave EventHandler?
getter/setter pair
onpointermove EventHandler?
getter/setter pair
onpointerout EventHandler?
getter/setter pair
onpointerover EventHandler?
getter/setter pair
onpointerup EventHandler?
getter/setter pair
onpopstate EventHandler?
getter/setter pair
onprogress EventHandler?
getter/setter pair
onratechange EventHandler?
getter/setter pair
onrejectionhandled EventHandler?
getter/setter pair
onreset EventHandler?
getter/setter pair
onresize EventHandler?
getter/setter pair
onscroll EventHandler?
getter/setter pair
onscrollend EventHandler?
getter/setter pair
onsecuritypolicyviolation EventHandler?
getter/setter pair
onseeked EventHandler?
getter/setter pair
onseeking EventHandler?
getter/setter pair
onselect EventHandler?
getter/setter pair
onselectionchange EventHandler?
getter/setter pair
onselectstart EventHandler?
getter/setter pair
onslotchange EventHandler?
getter/setter pair
onstalled EventHandler?
getter/setter pair
onstorage EventHandler?
getter/setter pair
onsubmit EventHandler?
getter/setter pair
onsuspend EventHandler?
getter/setter pair
ontimeupdate EventHandler?
getter/setter pair
ontoggle EventHandler?
getter/setter pair
ontouchcancel EventHandler?
getter/setter pair
ontouchend EventHandler?
getter/setter pair
ontouchmove EventHandler?
getter/setter pair
ontouchstart EventHandler?
getter/setter pair
ontransitioncancel EventHandler?
getter/setter pair
ontransitionend EventHandler?
getter/setter pair
ontransitionrun EventHandler?
getter/setter pair
ontransitionstart EventHandler?
getter/setter pair
onunhandledrejection EventHandler?
getter/setter pair
onunload EventHandler?
getter/setter pair
onvolumechange EventHandler?
getter/setter pair
onwaiting EventHandler?
getter/setter pair
onwheel EventHandler?
getter/setter pair
opener JSAny?
The Window interface's opener property returns a reference to the window that opened the window, either with Window.open, or by navigating a link with a target attribute.
getter/setter pair
orientation int
Returns the orientation in degrees (in 90-degree increments) of the viewport relative to the device's natural orientation.
no setter
origin String
The origin read-only property of the Window interface returns the origin of the global scope, serialized as a string.
no setter
outerHeight int
The Window.outerHeight read-only property returns the height in pixels of the whole browser window, including any sidebar, window chrome, and window-resizing borders/handles.
no setter
outerWidth int
Window.outerWidth read-only property returns the width of the outside of the browser window. It represents the width of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.
no setter
parent Window?
The Window.parent property is a reference to the parent of the current window or subframe.
no setter
performance Performance
The performance property of the Window interface returns a Performance object, which can be used to gather performance information about code running in the window's scope.
no setter
personalbar BarProp
Returns the personalbar object.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scheduler Scheduler
The scheduler read-only property of the Window interface is the entry point for using the Prioritized Task Scheduling API.
no setter
screen Screen
The Window property screen returns a reference to the screen object associated with the window. The screen object, implementing the Screen interface, is a special object for inspecting properties of the screen on which the current window is being rendered.
no setter
screenLeft int
The Window.screenLeft read-only property returns the horizontal distance, in CSS pixels, from the left border of the user's browser viewport to the left side of the screen.
no setter
screenTop int
The Window.screenTop read-only property returns the vertical distance, in CSS pixels, from the top border of the user's browser viewport to the top side of the screen.
no setter
screenX int
The Window.screenX read-only property returns the horizontal distance, in CSS pixels, of the left border of the user's browser viewport to the left side of the screen.
no setter
screenY int
The Window.screenY read-only property returns the vertical distance, in CSS pixels, of the top border of the user's browser viewport to the top edge of the screen.
no setter
scrollbars BarProp
Returns the scrollbars object.
no setter
scrollX double
The read-only scrollX property of the Window interface returns the number of pixels by which the document is currently scrolled horizontally. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number. You can get the number of pixels the document is scrolled vertically from the Window.scrollY property.
no setter
scrollY double
The read-only scrollY property of the Window interface returns the number of pixels by which the document is currently scrolled vertically. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number. You can get the number of pixels the document is scrolled horizontally from the Window.scrollX property.
no setter
self Window
The Window.self read-only property returns the window itself, as a . It can be used with dot notation on a window object (that is, window.self) or standalone (self). The advantage of the standalone notation is that a similar notation exists for non-window contexts, such as in Worker. By using self, you can refer to the global scope in a way that will work not only in a window context (self will resolve to window.self) but also in a worker context (self will then resolve to WorkerGlobalScope.self).
no setter
sessionStorage Storage
The read-only sessionStorage property accesses a session Storage object for the current . sessionStorage is similar to Window.localStorage; the difference is that while data in localStorage doesn't expire, data in sessionStorage is cleared when the page session ends.
no setter
speechSynthesis SpeechSynthesis
The speechSynthesis read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality.
no setter
status String
The status property of the Window interface was originally intended to set the text in the status bar at the bottom of the browser window. However, the HTML standard now requires setting window.status to have no effect on the text displayed in the status bar.
getter/setter pair
statusbar BarProp
Returns the statusbar object.
no setter
toolbar BarProp
Returns the toolbar object.
no setter
top Window?
Returns a reference to the topmost window in the window hierarchy.
no setter
trustedTypes TrustedTypePolicyFactory
The trustedTypes read-only property of the Window interface returns the TrustedTypePolicyFactory object associated with the global object, providing the entry point for using the Trusted Types API.
no setter
visualViewport VisualViewport?
The visualViewport read-only property of the Window interface returns a VisualViewport object representing the visual viewport for a given window, or null if current document is not fully active.
no setter
window Window
The window property of a Window object points to the window object itself.
no setter

Methods

addEventListener(String type, EventListener? callback, [JSAny options]) → void
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
inherited
alert([String message]) → void
window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog.
atob(String data) String
The atob() method of the Window interface decodes a string of data which has been encoded using encoding. You can use the Window.btoa method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the atob() method to decode the data again. For example, you can encode, transmit, and decode control characters such as values 0 through 31.
blur() → void
The Window.blur() method does nothing.
btoa(String data) String
The btoa() method of the Window interface creates a -encoded string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data).
cancelAnimationFrame(int handle) → void
The window.cancelAnimationFrame() method cancels an animation frame request previously scheduled through a call to window.requestAnimationFrame.
cancelIdleCallback(int handle) → void
The window.cancelIdleCallback() method cancels a callback previously scheduled with window.requestIdleCallback.
captureEvents() → void
The Window.captureEvents() method does nothing.
clearInterval([int id]) → void
clearTimeout([int id]) → void
close() → void
The Window.close() method closes the current window, or the window on which it was called.
confirm([String message]) bool
window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.
createImageBitmap(ImageBitmapSource image, [JSAny optionsOrSx, int sy, int sw, int sh, ImageBitmapOptions options]) JSPromise<ImageBitmap>
dispatchEvent(Event event) bool
The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().
inherited
fetch(RequestInfo input, [RequestInit init]) JSPromise<Response>
focus() → void
Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.
getComputedStyle(Element elt, [String? pseudoElt]) CSSStyleDeclaration
The Window.getComputedStyle() method returns an object containing the values of all CSS properties of an element, after applying active stylesheets and resolving any basic computation those values may contain.
getSelection() Selection?
The Window.getSelection() method returns a Selection object representing the range of text selected by the user or the current position of the caret.
matchMedia(String query) MediaQueryList
The Window interface's matchMedia() method returns a new MediaQueryList object that can then be used to determine if the document matches the media query string, as well as to monitor the document to detect when it matches (or stops matching) that media query.
moveBy(int x, int y) → void
The moveBy() method of the Window interface moves the current window by a specified amount.
moveTo(int x, int y) → void
The moveTo() method of the Window interface moves the current window to the specified coordinates.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open([String url, String target, String features]) Window?
The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.
postMessage(JSAny? message, [JSAny optionsOrTargetOrigin, JSArray<JSObject> transfer]) → void
The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
print() → void
Opens the print dialog to print the current document.
prompt([String message, String default_]) String?
window.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog.
queueMicrotask(VoidFunction callback) → void
releaseEvents() → void
Releases the window from trapping events of a specific type.
removeEventListener(String type, EventListener? callback, [JSAny options]) → void
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
inherited
reportError(JSAny? e) → void
requestAnimationFrame(FrameRequestCallback callback) int
The window.requestAnimationFrame() method tells the browser you wish to perform an animation. It requests the browser to call a user-supplied callback function before the next repaint.
requestIdleCallback(IdleRequestCallback callback, [IdleRequestOptions options]) int
The window.requestIdleCallback() method queues a function to be called during a browser's idle periods. This enables developers to perform background and low priority work on the main event loop, without impacting latency-critical events such as animation and input response. Functions are generally called in first-in-first-out order; however, callbacks which have a timeout specified may be called out-of-order if necessary in order to run them before the timeout elapses.
resizeBy(int x, int y) → void
The Window.resizeBy() method resizes the current window by a specified amount.
resizeTo(int width, int height) → void
The Window.resizeTo() method dynamically resizes the window.
scroll([JSAny optionsOrX, num y]) → void
The Window.scroll() method scrolls the window to a particular place in the document.
scrollBy([JSAny optionsOrX, num y]) → void
The Window.scrollBy() method scrolls the document in the window by the given amount.
scrollTo([JSAny optionsOrX, num y]) → void
Window.scrollTo() scrolls to a particular set of coordinates in the document.
setInterval(TimerHandler handler, JSAny? arguments, [int timeout]) int
setTimeout(TimerHandler handler, JSAny? arguments, [int timeout]) int
stop() → void
The window.stop() stops further resource loading in the current browsing context, equivalent to the stop button in the browser.
structuredClone(JSAny? value, [StructuredSerializeOptions options]) JSAny?
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited