JavaScript "screen" property with Dual screens
Posted: Tue Jun 20, 2006 9:00 am
Is there a *clean* way to detect if someone is using dual screens in JS?
Basically I need to use DHTML to position something on a screen and have just discovered on my work machine which has two monitors at 1280 width each my calculation breaks since the screen.width property returns the size of the two monitors combined. Of course, nobody would ever being using both screens for a single window (and in Gnome I can't maximize if I do that) so I need to get the width of just the one screen.
I've written a function:
But is there a better way to work it out? My code is basically seeing if it's closer to an 8/3 ratio than a 4/3 ratio and although it works it seems a bit fudgey.
Basically I need to use DHTML to position something on a screen and have just discovered on my work machine which has two monitors at 1280 width each my calculation breaks since the screen.width property returns the size of the two monitors combined. Of course, nobody would ever being using both screens for a single window (and in Gnome I can't maximize if I do that) so I need to get the width of just the one screen.
I've written a function:
Code: Select all
function isDualScreen()
{
var res = screen.width/screen.height;
if (Math.abs((res - (4/3))) < Math.abs((res - (8/3))))
{
return false;
}
else
{
return true;
}
}