在我本地測試當中:
在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的標準在作怪啊
如果在頁面中新增這行標記的話
在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高)
js獲取頁面高度寬度
關於獲取各種瀏覽器可見視窗大小的一點點研究。在我本地測試當中 在ie firefox opera下都可以使用 document.body.clientwidth document.body.clientheight即可獲得,很簡單,很方便。而在公司專案當中 opera仍然使用 document.bo...
jq獲取頁面高度 JQuery獲取頁面高度寬度
alert window height 瀏覽器當前視窗可視區域高度 alert document height 瀏覽器當前視窗文件的高度 alert document.body height 瀏覽器當前視窗文件body的高度 alert document.body outerheight true ...
獲取頁面高度和可見高度
document.body.clientwidth body物件寬度 document.body.clientheight body物件高度 document.documentelement.clientwidth 可見區域寬度 document.documentelement.clientheig...