popup open position in chrome

帅比萌擦擦* 提交于 2019-11-28 00:42:19

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.

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).

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:

https://code.google.com/p/chromium/issues/detail?id=137681

I know this is an old post but here's my solution to it. Just use the "avail*" properties of the screen object:

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.

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...

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...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!