gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 03:14:51 26 4
gpt4 key购买 nike

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

最佳答案

“window.open 双屏”搜索结果揭示了这个花哨的金 block :Dual Monitors and Window.open

"When the user clicks on a link that opens a new window using window.open. Make the window appear on the same monitor as its' parent."

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

Now that the code is written, you can now use window.open to open a window on the monitor the parent window is on.

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/browsers中并没有内置理解多显示器的功能,只是双屏桌面只是一个放大的单个笛卡尔平面,而不是两个离散的平面.

更新

链接失效了。使用 this waybackmachine link

关于javascript - 多显示器/双显示器系统上的 window.open() - 窗口在哪里弹出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16363474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com