DOM Window Interface
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
| Name | Description |
|---|---|
Window.innerWidth | The innerWidth property returns the width of the browser's viewport in pixels. |
Window.localStorage | The localStorage property gives access to storage that keeps string data in the browser with no expiry, so it survives page reloads and restarts. |
Window.location | The location property gives information about the current URL and lets you navigate to another page. |
Window.sessionStorage | The sessionStorage property gives access to storage that keeps string data only for the current browser tab, clearing it when the tab closes. |
Methods
| Name | Description |
|---|---|
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
| Name | Description |
|---|---|
Window: load event | The window's load event fires when the whole page has loaded, including images, style sheets and iframes. |
Window: resize event | The resize event fires on the window whenever the viewport changes size. |
Window: scroll event | The scroll event fires when the page or a scrollable element is scrolled. |
Example
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.
Desktop





Tablets & Mobile





