頁面/文檔高度目前受制於供應商(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