1 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
提供你一個(gè)函數(shù),獲取瀏覽器顯示部分的高度,兼容所有主流瀏覽器
<script>
function getWindowSize() {
var client = {
x:0,
y:0
};
if(typeof document.compatMode != 'undefined' && document.compatMode == 'CSS1Compat') {
client.x = document.documentElement.clientWidth;
client.y = document.documentElement.clientHeight;
} else if(typeof document.body != 'undefined' && (document.body.scrollLeft || document.body.scrollTop)) {
client.x = document.body.clientWidth;
client.y = document.body.clientHeight;
}
return client;
}
function getsize(){
var size = getWindowSize();
document.getElementById("width").value = size.x;
document.getElementById("height").value = size.y;
}
</script>
<body onresize="getsize()">
width:<input type="text" id="width" /><br />
height:<input type="text" id="height" />
</body>
- 1 回答
- 0 關(guān)注
- 537 瀏覽
添加回答
舉報(bào)