我有一个具有不同屏幕分辨率的双显示器设置,当我访问 this page 时在 Chrome 中,它显示了两个屏幕的正确分辨率。但是 IE 只显示我的主屏幕的分辨率。它出现在 IE 中 window.screen.availWidth
和 window.screen.availHeight
仅返回主屏幕的值。
我可以获得运行 Internet Explorer 的第二个屏幕的屏幕分辨率吗?
最佳答案
使用在 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 制作半兼容代码。
关于javascript - Internet Explorer 中的 Window.screen 和多个显示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35265678/