js相關瀏覽器的寬度問題

 document.documentElement.clientHeight -->瀏覽器的高度

 
document.documentElement.scrollHeight 全文的高度
 
document.documentElement.scrollTop滾去的高度
 
 
 
<script>
 
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);
}
getInfo();
</script>
 
在IE、FireFox、Opera下都可以使用
document.body.clientWidth
document.body.clientHeight
即可獲得,很簡單,很方便。
而在公司項目當中:
Opera仍然使用
document.body.clientWidth
document.body.clientHeight
可是IE和FireFox則使用
document.documentElement.clientWidth
document.documentElement.clientHeight
原來是W3C的標準在作怪啊
<!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高)
 
 
 
 
 
//獲取滾動條的高度
function getPageScroll(){
var yScroll;
if (self.pageYOffset) {
 
yScroll = self.pageYOffset;
alert(yScroll)
} else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
 
yScroll = document.documentElement.scrollTop;
alert(yScroll)
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
alert("zhoujian")
//alert(yScroll)
//alert("zj"+document.body.scrollTop)
}
arrayPageScroll = new Array('',yScroll)
//alert(yScroll)
return arrayPageScroll;
}
//獲取頁面實際大小
function getPageSize(){
   
    var xScroll, yScroll;
   
    if (window.innerHeight && window.scrollMaxY) {   
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
   
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }   
   
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
 
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){   
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
 
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章