Testing for multiple screens with javascript

cross-browser, html, javascript

Solution

I didn't find the answer I needed anywhere on StackOverflow, so responding late to the several related threads here. The solution is, first, check for secondary display with `window.screen.isExtended`. Then `await window.getScreenDetails()`, which returns an object that includes an array of screens.

Very thorough explanation here: https://web.dev/multi-screen-window-placement/

Problem

Is it possible to tell if the user of a website is using multiple monitors? I need to find the position of a popup but it's quite likely the user will have a multiple monitor setup. Whilst `window.screenX` etc. will give the position of the browser window it's useless for multiple monitors.

Original source