Favorites

DOM Window Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

The Window interface represents the browser window or tab containing the page. The global window object holds timers, dialogs, storage, location and screen information.

Description

The Window interface represents the window or tab containing a document. The global window object is the global scope of scripts in the page, so its members, such as setTimeout(), alert(), fetch(), localStorage, location and document, can be used without writing window. first.

It also provides the viewport size (innerWidth, innerHeight), scrolling (scrollY, scrollTo()), media queries (matchMedia()), computed styles (getComputedStyle()) and window events such as load, resize and scroll. Each iframe has its own window.

In the browser, window, self and globalThis all refer to the same object in the main page, while web workers have no window and use self. Global variables declared with var and function declarations at the top level of a classic script become properties of window, which is why modules, whose variables stay private, are safer for larger applications.

Properties

NameDescription
Window.innerWidthThe innerWidth property returns the width of the browser's viewport in pixels.
Window.localStorageThe localStorage property gives access to storage that keeps string data in the browser with no expiry, so it survives page reloads and restarts.
Window.locationThe location property gives information about the current URL and lets you navigate to another page.
Window.sessionStorageThe sessionStorage property gives access to storage that keeps string data only for the current browser tab, clearing it when the tab closes.

Methods

NameDescription
Window.alert()The alert() method shows a simple message box and waits until the user dismisses it.
Window.clearInterval()The clearInterval() method stops a repeating timer created with setInterval().
Window.clearTimeout()The clearTimeout() method cancels a timer set with setTimeout() before it runs.
Window.confirm()The confirm() method shows a dialog with OK and Cancel buttons and returns true or false depending on the user's choice.
Window.fetch()The fetch() method makes a network request and returns a promise for the response.
Window.getComputedStyle()The getComputedStyle() method returns the final values of all CSS properties of an element, after style sheets, inheritance and inline styles are applied.
Window.matchMedia()The matchMedia() method checks a CSS media query from JavaScript, such as screen width or dark mode, and can notify you when the result changes.
Window.prompt()The prompt() method shows a dialog asking the user to type some text, and returns what they entered or null.
Window.requestAnimationFrame()The requestAnimationFrame() method runs a function just before the browser's next repaint, which makes it the right tool for smooth JavaScript animations.
Window.scrollTo()The scrollTo() method scrolls the page to a given position, optionally with a smooth animation.
Window.setInterval()The setInterval() method runs a function repeatedly, with a fixed delay between each run, until it is stopped with clearInterval().
Window.setTimeout()The setTimeout() method runs a function once, after a delay in milliseconds.

Events

NameDescription
Window: load eventThe window's load event fires when the whole page has loaded, including images, style sheets and iframes.
Window: resize eventThe resize event fires on the window whenever the viewport changes size.
Window: scroll eventThe scroll event fires when the page or a scrollable element is scrolled.

Example

console.log(window === globalThis);
console.log(window.innerWidth + ' x ' + window.innerHeight);
console.log(typeof window.setTimeout, typeof window.document);
var globalVar = 1;
console.log(window.globalVar);

Browser Support

The following information will show you the current browser support for the Window interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee