JavaScript 獲取頁面高度(多種瀏覽器)
function getInfo() { var s = ""; s += " 網頁可見區域寬:"+ document.body.clientWidth; s += " 網頁可見區域高:"+ document.body.clientHeight; s += " 網頁可見區域寬:"+ document.body.offsetWidth + " (包括邊線和捲軸的寬)"; s += " 網頁可見區域高:"+ document.body.offsetHeight + " (包括邊線的寬)"; s += " 網頁正文全文寬:"+ document.body.scrollWidth; s += " 網頁正文全文高:"+ document.body.scrollHeight; s += " 網頁被卷去的高(ff):"+ document.body.scrollTop; s += " 網頁被卷去的高(ie):"+ document.documentElement.scrollTop; s += " 網頁被卷去的左:"+ document.body.scrollLeft; s += " 網頁正文部分上:"+ window.screenTop; s += " 網頁正文部分左:"+ window.screenLeft; s += " 螢幕解析度的高:"+ window.screen.height; s += " 螢幕解析度的寬:"+ window.screen.width; s += " 螢幕可用工作區高度:"+ window.screen.availHeight; s += " 螢幕可用工作區寬度:"+ window.screen.availWidth; s += " 你的螢幕設置是 "+ window.screen.colorDepth +" 位彩色"; s += " 你的螢幕設置 "+ window.screen.deviceXDPI +" 像素/英寸"; //alert (s); }
*—————————————————-*
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
在IE中:
document.body.clientWidth ==> BODY對象寬度 document.body.clientHeight ==> BODY對象高度 document.documentElement.clientWidth ==> 可見區域寬度 document.documentElement.clientHeight ==> 可見區域高度
在FireFox中:
document.body.clientWidth ==> BODY對象寬度
document.body.clientHeight ==> BODY對象高度
document.documentElement.clientWidth ==> 可見區域寬度
document.documentElement.clientHeight ==> 可見區域高度
在Opera中:
document.body.clientWidth ==> 可見區域寬度
document.body.clientHeight ==> 可見區域高度
document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬) document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)
而如果沒有定義W3C的標準,則 IE為:
document.documentElement.clientWidth ==> 0
document.documentElement.clientHeight ==> 0
FireFox為:
document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬)
document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)
Opera為:
document.documentElement.clientWidth ==> 頁面對象寬度(即BODY對象寬度加上Margin寬)
document.documentElement.clientHeight ==> 頁面對象高度(即BODY對象高度加上Margin高)
from :
http://www.dotblogs.com.tw/aquarius6913/archive/2011/01/03/20538.aspx