1.IE11上想通过ActiveXObject判断显示器的个数,在双屏的情况下,但是返回的信息只有一个显示器的信息。
- 代码如下:
export function openPageActiveObject(windows = []) {
const flag = checkBrowserIsIE();
if (!flag) {
return;
}
const locator = new ActiveXObject("WbemScripting.SWbemLocator"); // eslint-disable-line
const service = locator.ConnectServer(".");
// 显示器
// eslint-disable-next-line no-undef
const properties = service.ExecQuery("SELECT * FROM Win32_DesktopMonitor");
// eslint-disable-next-line no-undef
const xsq = new Enumerator(properties);
// 得到所有显示器的分辨率
let xsq1Width;
let xsq1Height;
let xsq2Width;
let xsq2Height;
let i = 1;
xsq.moveFirst();
for (; !xsq.atEnd(); xsq.moveNext()) {
// console.log("============== xsq.item():",xsq.item());
if (i === 1) {
xsq1Width = xsq.item().ScreenWidth;
xsq1Height = xsq.item().ScreenHeight;
} else if (i === 2) {
xsq2Width = xsq.item().ScreenWidth;
xsq2Height = xsq.item().ScreenHeight;
}
i++;
}
// 判断单双屏
if (
(xsq1Width == null && xsq1Height == null) ||
(xsq2Width == null && xsq2Height == null)
) {
console.log("========单屏")
} else {
console.log("=========双屏")
}
}