Page 1 of 1

JavaScript "screen" property with Dual screens

Posted: Tue Jun 20, 2006 9:00 am
by Chris Corbyn
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:

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;
	}
}
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.

Posted: Tue Jun 20, 2006 9:11 am
by feyd
What does screen.availHeight and screen.availWidth return?

There's also a possibility of using window.innerHeight and window.outerHeight.. but those are Mozilla specific, that I remember.

Posted: Tue Jun 20, 2006 9:40 am
by Chris Corbyn
feyd wrote:What does screen.availHeight and screen.availWidth return?

There's also a possibility of using window.innerHeight and window.outerHeight.. but those are Mozilla specific, that I remember.
screen.availWidth and height do the same thing :(

Yeah, the innerWidth and innerHeight stuff doesn't work in IE which sucks.

Thanks anyway :D

Posted: Tue Jun 20, 2006 12:29 pm
by Chris Corbyn
FYI document.body.clientHeight and width are the IE equivalent of innerHeight and innerWidth. Just found that out myself :)