我有一个具有不同屏幕分辨率的双显示器设置,当我在Chrome中访问this page时,它会显示两个屏幕的正确解析。但IE只显示我的主屏幕的分辨率。它出现在IE window.screen.availWidth
中,而window.screen.availHeight
仅返回主屏幕的值。
我可以获得运行Internet Explorer的第二个屏幕的屏幕分辨率吗?
答案 0 :(得分:5)
使用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);
我知道它并不多,但它至少可以让你评估客户端是否在双显示器上以及设备的宽度。
IE所做的唯一一件事就是在所有监控器之间平均分配分辨率。
因此需要总宽度并将其除以监视器数量。
我有3个显示器,2个是1920 x 1080,另一个是1600 x 900,我的测试和IE给了左边的位置1745 0 -1745所以是的......总的来说IE是关闭的,但是希望这个小的片段将帮助您,或者其他人进一步为IE制作半兼容代码。