的窗口.在Chrome的第二个显示器上打开'
`window.open` on the second monitor in Chrome
当我使用firefox然后使用window.open('blah.com','blah','left=-30,top=-300');
时,弹出窗口在我的第一个显示上方的第二个显示中打开,但在chrome中,弹出窗口只是在left=0,top=0
打开。是否有一个原因,为什么铬是这样做,我将如何解决这个问题?
谢谢!
这是Chrome浏览器在二级显示器上打开弹出窗口时的一个错误。Chrome的人似乎说这是一个安全问题(尽管这是一个安全问题超出了我的范围)。
现在,在不存在的辅助监视器上打开弹出窗口,我可以理解这是一个安全问题,但是……无论什么。
这里有一个关于此事的讨论链接:
https://code.google.com/p/chromium/issues/detail?id=137681我知道这是一个旧的帖子,但这是我的解决方案。只需使用屏幕对象的"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);
基本上,就是"window.screen"。
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);
铬…
看看这个StackOverflow的post Center在屏幕上弹出窗口?
几年前我对这个功能做了一点升级。
function multipleScreenPopup(url, title, w, h, centered = true, moveRight = 0, moveDown = 0, resizable = "no") {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = 0;
var top = 0;
if (centered === true) {
left = ((width / 2) - (w / 2)) + dualScreenLeft;
top = ((height / 2) - (h / 2)) + dualScreenTop;
} else {
left = dualScreenLeft + moveRight;
top = dualScreenTop + moveDown;
}
var newWindow = window.open(url, title, 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=' + resizable + ', width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
}
// centered as of the monitor that fired on it
multipleScreenPopup('https://google.com', '_blank', 500, 500);
// move from the left and from the top
multipleScreenPopup('https://yahoo.com', '_blank', 500, 500, false, 200, 200);
我知道这篇文章很旧,但我也有过类似的问题:
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);
—在Firefox中居中,但在Chrome中不居中。另外,请注意,这并不在显示区域之外…
这个方法是可行的,尽管这个方法是实验性的,将来可能不会起作用
var screenDetails = await window.getScreenDetails()
if (screen.isExtended && screenDetails.screens.length > 1) {
var newWindow = window.open(
"https://ya.ru",
"New Window",
`popup,width=${myWidth},height=${myHeight},left=0,top=0`
);
newWindow.moveTo(screenDetails.screens[1].left + myMargin, 0);
}
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 防止Iframe窗体在新窗口中打开
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 调整窗口大小时,可拖动的对象会出现在容器外部
- Javascript排序的图像弹出窗口..可以't单独弹出
- 窗口大小html css
- 弹出窗口出现,然后退出
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- Javascript更新孙窗口中的表单元素
- 如何在选项卡上定义属性'的主窗口对象
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- 召回窗口加载事件 - javascript
- 为什么不显示警报窗口
- 自动打开另一台显示器上的浏览器窗口
- 是否可以将新打开的窗口移动到另一个显示器
- 你能控制用Javascript创建的窗口显示在哪个显示器上吗
- 在双显示器上复制弹出窗口显示
- 在显示器中央打开一个弹出窗口
- 的窗口.在Chrome的第二个显示器上打开'
- 从双显示器上的Chrome扩展程序打开弹出窗口