ActiveXObject获取显示器信息不准确

1.IE11上想通过ActiveXObject判断显示器的个数,在双屏的情况下,但是返回的信息只有一个显示器的信息。

  1. 代码如下:
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("=========双屏")
        
    }
}
阅读 2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进