页面/文档高度目前受制于供应商(IE/Moz/Apple/...)实施,并且没有标准且一致的跨浏览器结果。看看jQuery .height()方法;
if (jQuery.isWindow(elem)) {
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
// 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
var docElemProp = elem.document.documentElement[ "client" + name ],
body = elem.document.body;
return elem.document.compatMode === "CSS1Compat" && docElemProp ||
body && body[ "client" + name ] || docElemProp;
// Get document width or height
} else if (elem.nodeType === 9) {
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
return Math.max(
elem.documentElement["client" + name],
elem.body["scroll" + name], elem.documentElement["scroll" + name],
elem.body["offset" + name], elem.documentElement["offset" + name]
);
节点类型=== 9平均DOCUMENT_NODE:http://www.javascriptkit.com/domref/nodetype.shtml 所以没有jQuery代码的解决方案应该是这样的:
var height = Math.max(
elem.documentElement.clientHeight,
elem.body.scrollHeight, elem.documentElement.scrollHeight,
elem.body.offsetHeight, elem.documentElement.offsetHeight)
[使用JavaScript整个文档的获取高度]的
可能重复(HTTP://计算器.com/questions/1145850/get-height-of-entire-document-with-javascript) – 2012-02-24 11:38:19
应该这样做。谢谢Felix。 – 2012-02-24 11:53:01
你有使用jQuery的能力吗?如果是这样,这里的答案可能会对你有所帮助:http://stackoverflow.com/a/1304384/104435 – soniiic 2012-02-24 11:37:18