多显示器/双显示器系统上的 window.open() - 窗口在哪里弹出?

2023-12-12

在多显示器系统上使用 javascript window.open() 时,如何控制弹出窗口打开哪个显示器或显示空间中的哪个位置?对我来说,它似乎失去了控制,而且它的行为是随机的。


“window.open 双屏”搜索的结果揭示了这个奇特的金块:双显示器和 Window.open

“当用户单击打开新窗口的链接时,使用 窗口.打开。使窗口与其所在的显示器显示在同一台显示器上 家长。”

// 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;

现在代码已经写好了,你现在可以使用window.open来打开一个 父窗口所在的监视器上的窗口。

window.open(thePage, 'windowName', 'resizable=1, scrollbars=1, fullscreen=0, height=200, width=650, screenX=' + window.leftScreenBoundry() + ' , left=' + window.leftScreenBoundry() + ', toolbar=0, menubar=0, status=1');

如果它成功地允许您在启动它的文档所在的同一屏幕上打开弹出窗口,那么通过类似的努力,人们应该能够修改它以使其表现不同。

请注意,正如代码长度所暗示的那样,jquery/javascript/浏览器中没有用于理解多个显示器的内置函数,只是双屏桌面只是放大的单个笛卡尔平面而不是两个离散的平面。

Update

链接已失效。使用这样返回机器链接

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

多显示器/双显示器系统上的 window.open() - 窗口在哪里弹出? 的相关文章

随机推荐