Get to know MDN better
This guide explains how to use the Window Management API. The example code seen below is taken from our Multi-window learning environment example (see the source code).
You can feature detect the Window Management API by checking for the existence of getScreenDetails in the current window instance. For example, you might want to provide a button to open a multi-window display if the API is supported, or a different experience such as creating links to the different pages if it isn't:
The core of the Windows Management API is the Window.getScreenDetails() method, which returns an object containing details of all the screens available to the user's system:
When getScreenDetails() is invoked, the user will be asked for permission to manage windows on all their displays (the status of this permission can be checked using Permissions.query() to query window-management). If the user grants permission, a ScreenDetails object is returned. This object contains the following properties:
ScreenDetailed objects inherit the properties of the Screen interface, and contain useful information for placing windows on specific screens.
Note: You can gate functionality based on whether the user has more than one screen available using the Window.screen.isExtended property. This returns true if the device has multiple screens, and false if not.
You'll still need to use Window.open() to open and manage windows, but the above provides you with better information for doing so in a multi-screen environment. For example, a utility function might look like so:
You would then invoke this function and open windows on specific screens like this:
After opening each window, we add a reference to the windowRefs array. This allows you to, for example, close them all when one window is closed:
Note: In our experiments, the setInterval() polling method shown above seemed to work best for detecting window closure in the case of multiple windows. Using events such as beforeunload, pagehide, or visibilitychange proved unreliable because, when opening multiple windows at the same time, the rapid shift in focus/visibility seemed to fire the handler function prematurely.
Note: One concern with the above example is that it uses constant values to represent the size of the Chrome window UI portions in the calculations — WINDOW_CHROME_X and WINDOW_CHROME_Y — to get the window size calculations correct. To create precisely-sized windows on other future implementations of the API, you'd need to keep a small library of browser chrome sizes, and employ browser detection to discover which browser is rendering your app and choose the correct size for calculations. Or you can rely on less precise window sizes.
In modern browsers, a separate user gesture event is required for each Window.open() call, for security purposes. This prevents sites from spamming users with lots of windows. However, this poses an issue for multi-window applications. To work around this limitation, you can design your applications to:
In our demo application, we have gone for the third option. Our openWindow() function contains the following section:
If the browser blocks a new window, the resulting windowRef will be null. In this case we run our closeAllWindows() function to close any windows that did manage to open before the blocking started, and show a popover element that explains how to disable the popup blocker.
If you want to open a single window on each available display that is the full width and height of the display, you could use a pattern like this:
The Window Management API provides some events for responding to changes in the available screens:
The ScreenDetails screenschange eventFired when screens are connected to or disconnected from the system.
The ScreenDetails currentscreenchange eventFired when the window's current screen changes in some way.
The Screen change eventFired on a specific screen when it changes in some way.
So for example, you could use the screenschange event to detect when the available screens have changed (perhaps when a screen is plugged in or unplugged), report the change, close all windows, and update window arrangements to suit the new configuration:
The Window Management API adds a new screen option to the requestFullscreen() method that allows you to specify on which screen you want to put the element in fullscreen mode. For example, if you want to make it fullscreen on the primary OS screen:
This page was last modified on Apr 28, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.