Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window.screen in Internet Explorer and more than one monitor

I have a dual monitor setup with different screen resolutions and when I visit this page in Chrome it shows the right resoltion for both screens. But IE only shows the resolution of my primary screen. It appears than in IE window.screen.availWidth and window.screen.availHeight only returns the values for the primary screen. Can I get the screen resolution for the second screen running Internet Explorer?

like image 422
Marcel B Avatar asked Feb 08 '16 09:02

Marcel B


1 Answers

Using ancient code found at http://archive.cpradio.org/code/javascript/dual-monitors-and-windowopen/

function FindLeftWindowBoundry()
{
	// In Internet Explorer window.screenLeft is the window's left boundry
	if (window.screenLeft)
	{
		return window.screenLeft;
	}
	
	// In Firefox window.screenX is the window's left boundry
	if (window.screenX)
		return window.screenX;
		
	return 0;
}

window.leftWindowBoundry = FindLeftWindowBoundry;

// Find Left Boundry of the Screen/Monitor
function FindLeftScreenBoundry()
{
	// Check if the window is off the primary monitor in a positive axis
	// X,Y                  X,Y                    S = Screen, W = Window
	// 0,0  ----------   1280,0  ----------
	//     |          |         |  ---     |
	//     |          |         | | W |    |
	//     |        S |         |  ---   S |
	//      ----------           ----------
	if (window.leftWindowBoundry() > window.screen.width)
	{
		return window.leftWindowBoundry() - (window.leftWindowBoundry() - window.screen.width);
	}
	
	// Check if the window is off the primary monitor in a negative axis
	// X,Y                  X,Y                    S = Screen, W = Window
	// 0,0  ----------  -1280,0  ----------
	//     |          |         |  ---     |
	//     |          |         | | W |    |
	//     |        S |         |  ---   S |
	//      ----------           ----------
	// This only works in Firefox at the moment due to a bug in Internet Explorer opening new windows into a negative axis
	// However, you can move opened windows into a negative axis as a workaround
	if (window.leftWindowBoundry() < 0 && window.leftWindowBoundry() > (window.screen.width * -1))
	{
		return (window.screen.width * -1);
	}
	
	// If neither of the above, the monitor is on the primary monitor whose's screen X should be 0
	return 0;
}

window.leftScreenBoundry = FindLeftScreenBoundry;

console.log(window.screen.width);
console.log(window.leftScreenBoundry());

console.log(window.screen.height);

I know it's not much, but it will at least allow you to assess if the client is on a dual monitor set and how wide the set is.

The only f*ed up thing IE does is distribute the resolution evenly among all montors.

So it takes total width and divides it by number of monitors.

I have 3 monitors, 2 at 1920 x 1080 and one at 1600 x 900 for my testing and IE gave the left position as 1745 0 -1745 so yea... something is off with IE in all, but hopefull this little snippet will help you, or someone else a bit further is making semi compatible code for IE.

like image 64
Tschallacka Avatar answered Nov 15 '22 13:11

Tschallacka