在ie8中获取进入浏览器窗口的高度 [英] Get height of enter browser window in ie8

查看:459
本文介绍了在ie8中获取进入浏览器窗口的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按宽度调整浏览器的大小(我知道......我知道......),并希望维护用户当前浏览器的高度,我正在努力让它正常工作在IE8下。

I'm trying to resize a browser (I know... I know...) by the width only, and would like to maintain the users current height of the browser and I'm struggling to get it working correctly under IE8.

如果我这样做:

window.resizeTo(document.documentElement.clientWidth, document.documentElement.clientHeight);

理论上应该保持完全相同的尺寸,我从高处丢失大约176个像素...大致有关滚动条的宽度。

Which should in theory, maintain the exact same size, I'm losing roughly 176 pixels from the height... and roughly about the width of the scrollbar.

我找不到任何可以提供整个浏览器窗口大小的属性。

I can't find any properties which would give me the correct size of the entire browser window.

推荐答案

这不是最佳解决方案,但可行。

This isn't the best solution, but it works.

首先,保存当前报告的高度:

First, save the current reported height:

var oldY = document.documentElement.clientHeight;

其次,将窗口大小设置为已知大小:

Second, set the window size to an a known size:

window.resizeTo(800, 600);

接下来通过从已知大小中减去报告的大小来确定填充量:

Next determine the amount of padding by subtracting the reported size from the known size:

var padX = 800 - document.documentElement.clientWidth;
var padY = 600 - document.documentElement.clientHeight;

最后,将宽度设置为所需的值加上 padX ,以及 oldY 加上 padY 的高度。

Finally, set the width to the desired value plus padX, and the height to the oldY plus padY.

window.resizeTo(desiredWidth + padX, oldY + padY);

此方法的缺点是用户可能会注意到窗口在第二步改变大​​小过程。

The downside to this method is that the user may notice the window changing size at the second step of the process.

这篇关于在ie8中获取进入浏览器窗口的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆