1 回答
TA贡献1818条经验 获得超11个赞
提供你一个函数,获取浏览器显示部分的高度,兼容所有主流浏览器
<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 关注
- 513 浏览
添加回答
举报