如何获得一致的javascript window.outerHeight跨浏览器? [英] how do I get a consistent javascript window.outerHeight cross browser?

查看:500
本文介绍了如何获得一致的javascript window.outerHeight跨浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个noob的问题,但...

Maybe this is a noob question but...

我有一个网站,我想让页脚一直出现在同一个地方。假设我的用户都在> = IE8,Chrome和Firefox我想这只是一个问题,得到Window.outerHeight。

I have a site where I want the footer to appear in the same place all the time. Assuming my users are all on >= IE8, Chrome and Firefox I figured it was just a question of getting the Window.outerHeight.

但是当我测量window.outerHeight它在FF v。Chrome v。IE中返回不同的值。

But when I measure the window.outerHeight it returns different values in FF v. Chrome v. IE.

此外,只是在视觉上做一些基本测量,显然500px DIV在我的

Plus, just doing some basic measurements visually, it's clear that a 500px DIV is not the same height on my monitors in Chrome as in FF as in IE.

SO:有一些公式可以可靠地用来转换像素大小的跨浏览器,以便可以设置一个正确的'max-height'为某个div,并知道它将在我的显示器上的IE,Chrome和FF相同的高度?

SO: Is there some 'formula' one can reliably use to convert pixel size cross browser so that one can set a proper 'max-height' for a certain div and know it will be the same height in my monitor on IE, Chrome and FF?

再次...我不是真正关心真正的普遍。 99%的用户将拥有这3个浏览器,所以如果我能得到这些,我会很高兴。

Again... I'm not really concerned about truly 'universal'. 99% of my users will have those 3 browsers so if I can get those OK, I'd be more than happy.

TIA,

--- JC

推荐答案

body.offsetHeight 。

for IE8 you could use document.body.offsetHeight.

但我建议只使用CSS:

but I would suggest to use only CSS:

<div id="footer" style="position: fixed; bottom: 0;"></div>

(例如: http://jsfiddle.net/5h8zj/

这篇关于如何获得一致的javascript window.outerHeight跨浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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