8

我正在使用 javascript 的 window.open 在用户单击指定宽度和高度 (760x581) 时打开浏览器窗口,这在 Internet Explorer、Safari 和 Firefox 上正常工作,但 Google Chrome 给我带来了问题。在其他浏览器中,高度被正确地用作内容的高度,但在 Google Chrome 中,它使实际浏览器窗口的高度为 581 像素而不是内容。有没有办法来解决这个问题?

<a href="http://domain.com/example.php" onclick="window.open('http://domain.com/example.php', '', 'width=760, height=581, top=15, left=15, toolbar=0, menubar=0, scrollbars=1, resizable=1, copyhistory=0, location=0, directories=0, status=1, titlebar=1, personalbar=0');return false">click here</a>
4

3 回答 3

4

So I messed with things more and discovered that some browsers supported the property innerHeight for window.open and the following worked as expected in all browsers with the desired content height at 775px with 50px added to Chrome only:

window.open($(this).attr('href'), 'videoplayer',
   'width=1242, height=775, innerHeight=825, location=no, menubar=no, status=no, titlebar=no, scrollbars=no'
);

I tested this in Chrome 6.0.472.63, Firefox 3.6, 3, and 2, IE 8 & 7, and Opera 10.62. When I was only using height Chrome would be about 50px too short and have scrollbars but all the browsers above were fine. With the added innerHeight property set at 50px more than what I want it worked in Chrome as well as all other browsers.

Update: It looks like this creates a problem in Safari with an added 50px of height. Will look into ways to get around that.

于 2010-10-14T16:47:31.697 回答
1

问题依然存在(Chrome17+),如果调用 window.open 时 height=600,结果窗口 innerheight 为 564px,短 36px(对于 Windows 上的标题栏)。标题栏高度取决于平台,所以这很烦人。

我的解决方案只是增加了高度的差异。

于 2011-12-03T08:24:40.043 回答
0

好吧,我在谷歌搜索了一个多小时后发现,谷歌浏览器就是这样做的,我们必须使用一种解决方法。除非找到更好的东西,否则我现在正在做的只是将以下 JS 放在我正在打开的页面上:

if (navigator.appVersion.indexOf('Chrome')>0) {
    window.resizeBy(0, 581 - window.innerHeight);
}
于 2010-08-12T02:54:20.200 回答