简体   繁体   English

在辅助屏幕上放置弹出窗口

[英]Positioning a popup on secondary screen

I'm trying to create a private web page for myself that would open a website as a popup window on my secondary monitor. 我正在尝试为自己创建一个私人网页,该网页将作为辅助监视器上的弹出窗口打开一个网站。 I can position the popup automatically within my main monitor, where the browser covers the whole screen, just fine, but when I try to automatically move the created popup window to my other screen, it simply refuses to go there. 我可以在我的主监视器中自动放置弹出窗口,浏览器可以覆盖整个屏幕,这很好,但是当我尝试自动将创建的弹出窗口移动到另一个屏幕时,它只是拒绝去那里。

The code I was trying with is 我正在尝试的代码是

window.open('https://tweetdeck.twitter.com','Tweetdeck','width=1664,height=488,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=-1680,top=591');

I also tried with .moveTo with same results. 我也尝试使用.moveTo获得相同的结果。

The top positioning works correctly, but left doesn't seem to have effect when it is less than 0. left=-1680,top=591 is the exact location I want to move it to (checked with autohotkey window spy), but Chrome doesn't seem to be willing to do that. top位置可以正常工作,但是当它小于0时, left位置似乎无效left=-1680,top=591是我要将其移动到的确切位置(已通过自动热键窗口间谍检查),但Chrome似乎不愿意这样做。

I have a feeling it might be due to position error correction , but the window in that position is very much on my desktop and fully visible. 我感觉这可能是由于位置错误校正造成的 ,但是该位置的窗口在我的桌面上非常多,并且完全可见。

Is there a way I could automatically move the window to the specified pixel coordinates in javascript? 有没有一种方法可以自动将窗口移动到javascript中的指定像素坐标?

Quite a challenging issue but I'm afraid it's impossible in dual view mode; 颇具挑战性的问题,但恐怕在dual view模式下是不可能的。 I have also two monitors working on dual view mode. 我也有两个在双视图模式下工作的显示器。 Check this out 看一下这个

if (!w || w.closed) {
    w = window.open("","links","menubar=0,scrollbars=0,width=600,height=480");
}
w.document.write("<p>X: " + w.screenX + "Y: " + w.screenY + "</p>");

// center in
w.moveTo((screen.width/2)-(640/2),(screen.height/2)-(480/2));
// horizontal positioning fails

// try the negative value
w.moveTo(-300,300); // it fails again

w.focus();
// it only works if you move the popup window by hand 
// after that it has already been instantiated

Maybe it could work if I merge my two screens, not sure. 如果不能合并两个屏幕,也许可以工作。 I'll check it in a meantime and post back the results here. 我将在此期间进行检查,并将结果发回此处。

EDIT Yes, it works if I merge my two screens in so-called horizontal span mode. EDIT是的,如果我以所谓的horizontal span模式合并两个屏幕,则它可以工作。

I believe there's another solution like building a tiny C/C++ app to handle the active window but isn't that weird :) 我相信还有另一种解决方案,例如构建一个小的C / C ++应用程序来处理活动窗口,但这并不奇怪:)

var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\PopupWinHandler.exe"; 
oShell.ShellExecute(commandtoRun,"","","open","1");

However, here is the jsBin experiment, so you can play around. 但是,这是jsBin实验,因此您可以尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM