Javascript chrome 中的弹出打开位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6754260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
popup open position in chrome
提问by Andrew
When I'm using firefox and then using window.open('blah.com','blah','left=-30,top=-300');
, the popup opens in my second display above my first one but in chrome, the popup just opens at left=0,top=0
. Is there a reason why chrome is doing this and how would I fix the problem?
当我使用 firefox 然后使用 时window.open('blah.com','blah','left=-30,top=-300');
,弹出窗口在我的第一个显示器上方的第二个显示器中打开,但在 chrome 中,弹出窗口仅在left=0,top=0
. chrome 这样做是否有原因,我将如何解决这个问题?
Thanks!
谢谢!
采纳答案by Graham
I think this is a bug in Chrome to be honest but I'm not aware of a fix at the moment as I'm new to JavaScript myself. Sorry I'm sure this not the answer you were looking for.
老实说,我认为这是 Chrome 中的一个错误,但由于我自己是 JavaScript 的新手,因此我目前不知道修复程序。抱歉,我确定这不是您要找的答案。
回答by Chris Jordan
This is a bug in Chrome when the pop-up window is opened on the secondary monitor. The Chrome folks seem to say that this is a security issue (though how this is a security issue is beyond me).
这是在辅助监视器上打开弹出窗口时 Chrome 中的错误。Chrome 的人似乎说这是一个安全问题(尽管我无法理解这是一个安全问题)。
Now, opening a pop-up window on a NON-EXISTENT secondary monitor, I could understand is a security issue, but... whatever.
现在,在不存在的辅助监视器上打开一个弹出窗口,我可以理解这是一个安全问题,但是......无论如何。
Here's a link to a discussion on the matter:
这是有关此问题的讨论的链接:
回答by Adrian Neatu
I know this is an old post but here's my solution to it. Just use the "avail*" properties of the screen object:
我知道这是一个旧帖子,但这是我的解决方案。只需使用屏幕对象的“avail*”属性:
var windowSize = {
width: 500,
height: 500,
};
var windowLocation = {
left: (window.screen.availLeft + (window.screen.availWidth / 2)) - (windowSize.width / 2),
top: (window.screen.availTop + (window.screen.availHeight / 2)) - (windowSize.height / 2)
};
window.open(http://example.com, '_blank', 'width=' + windowSize.width + ', height=' + windowSize.height + ', left=' + windowLocation.left + ', top=' + windowLocation.top);
Basically, the "window.screen.availLeft" gives you the other screens width so you can add you're normal center calculation to that.
基本上,“window.screen.availLeft”为您提供了其他屏幕宽度,因此您可以将正常的中心计算添加到其中。
回答by user2638430
var w = 300;
var h = 300;
var left = (window.screen.width/2)-(w/2);
var top = (window.screen.height/2)-(h/2);
var win = window.open("example.html", "_blank", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h);
win.moveTo(left, top);
for Chrome...
对于Chrome的...
回答by grasingerm
I know this post is old but I've had similar problems:
我知道这篇文章很旧,但我也遇到过类似的问题:
var w = 300;
var h = 300;
var left = (window.screen.width/2)-(w/2);
var top = (window.screen.height/2)-(h/2);
var win = window.open("example.html", "_blank", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
--centers the popup window in Firefox but not in Chrome. Also, notice, this is not outside the display area...
-- 将 Firefox 中的弹出窗口居中,但不在 Chrome 中。另外,请注意,这不在显示区域之外......