获得窗口高度 [英] Get the window height

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

问题描述

这令我感到沮丧。它应该是非常简单的东西,但我不能让它在IE中工作。我想得到当前窗口的高度:不是滚动高度,不是文档高度,而​​是实际窗口高度。我试过 window.innerHeight ,它返回 undefined document.documentElement.clientHeight ,它给出了滚动高度。

解决方案

对于当前的浏览器

  window.innerHeight 

对于IE 8及更低版本,使用

  document.documentElement.offsetHeight; 

如果您需要旧浏览器,请使用:



<窗口
中的pre> var height =innerHeight? window.innerHeight
:document.documentElement.offsetHeight;


This is frustrating me. It should be something really simple but I can't get it to work in IE. I want to get the height of the current window: Not the scroll height, not the document height, but the actual window height. I've tried window.innerHeight which returns undefined and document.documentElement.clientHeight which gives the scroll height.

解决方案

For current browsers

window.innerHeight 

For IE 8 and lower, use

document.documentElement.offsetHeight;

If you need older browsers, use:

var height = "innerHeight" in window 
               ? window.innerHeight
               : document.documentElement.offsetHeight; 

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

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