« Microsoft settles IBM antitrust claims | Main| I wonder if this works for XXL shirts? »

A challenge for JavaScript monkeys...

Category
Is there a way in a browser to detect if you are running in a dual monitor setup? A way to get the dimensions of each monitor? My usual fall back for such questions, Google, has failed to find the goods.

Anyone know if it's possible? Possible with a Java applet?

Comments

Gravatar Image1 - Alas, I don't believe this is possible with straight Javascript. You can certainly detect screen size and so forth (there's a standard "screen" object with properties to retrieve actual and available dimensions, bit depth, etc).

That said, if you run some test Javascript with those attributes on a dual screen system, I wonder what would happen? You could give this code a go (limited to available width and height, but you could easily add the other stuff):

function testScreen()
{
if (screen.availHeight)
{
alert("availHeight = " + screen.availHeight);
}

if (screen.availWidth)
{
alert("availWidth = " + screen.availWidth);
}
}

Gravatar Image2 - screen.availHeight/availWidth each return the available width and height of the primary monitor, and does not take into account dual monitors or whether the browser window is in a secondary or tertiary monitor.

Unfortunately, I haven't found a good way to detect dual monitors either.

Gravatar Image3 - The behavior I'm seeing is quite the opposite - my window takes all the real estate accross BOTH monitors.

Here's the script I'm using:
oWindow = window.open(....)
oWindow.moveTo(0, 0);
oWindow.resizeTo(window.screen.availWidth, window.screen.availHeight);

I just want my window to perform the same function as when user presses "Maximize" button....

Gravatar Image4 - I've recently bumped up against this problem and have had no luck whatsoever resolving it... until now. If anyone still cares, I have found a poor solution at best that probably only works with IE. As others have pointed out, window.screen.width only returns monitor 1's width. However, I noticed that IE doesn't want to make windows larger than the viewable footprint of the desktop.

Here's the clunky part, if you open a huge window, IE will reduce its size down to the largest that can be displayed on the two monitors. You can get the dimensions of the client area of that window (IE doesn't let you get the outter dimensions). With the dimensions of monitor one and the approximate dimensions of both monitors together, you can derive the approximate size of monitor 2.

What I've noticed in practice: I run a 1280x1024 monitor 2 with a 1024 x768 laptop monitor 1. The total dimensions I get are 2306x1007. Interestingly, I get this measurement even in I position this super sized window outside of the viewable desktop (i.e. left is @ 10000, top @ 0, hence I'm hiding that I'm measuring the monitors). Of course, the math would make is seem as though the second monitor's dimensions are 1282x1007 which is close but not exactly right. In any case, you can detect the second montior (window's clientWidth > screen.availWidth indicates more than more than one montior is involved) and you can get the approximate dimensions of the second monitor (much more accurate in width than height).

I've tested this with the second monitor @ 800x600 and the diensions returned were 1826x751. Clearly the least accurate dimension is the height. It appears the larger height is chosen as the basis for measurement.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::rolleyes:;-)