当前位置:Gxlcms > JavaScript > javascript获得网页窗口实际大小的示例代码_javascript技巧

javascript获得网页窗口实际大小的示例代码_javascript技巧

时间:2021-07-01 10:21:17 帮助过:8人阅读

javascript代码:
代码如下:

function get_page_size()
{
var re = {};
if (document.documentElement && document.documentElement.clientHeight)
{
var doc = document.documentElement;
re.width = (doc.clientWidth>doc.scrollWidth)?doc.clientWidth-1:doc.scrollWidth;
re.height = (doc.clientHeight>doc.scrollHeight)?doc.clientHeight:doc.scrollHeight;
}
else
{
var doc = document.body;
re.width = (window.innerWidth>doc.scrollWidth)?window.innerWidth:doc.scrollWidth;
re.height = (window.innerHeight>doc.scrollHeight)?window.innerHeight:doc.scrollHeight;
}
return re;
}
904 viewed 3 comment(s)

代码实例:
代码如下:





获取窗口大小
输出至两个文本框
document.form1.availHeight.value= re.width;
document.form1.availWidth.value= re.height;
return re;
}