Home  >  Article  >  Web Front-end  >  Javascript sample code to obtain the actual size of the web page window_javascript skills

Javascript sample code to obtain the actual size of the web page window_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:22:22998browse

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)

代码实例:
复制代码 代码如下:





获取窗口大小




浏览器窗口 的 实际高度:



浏览器窗口 的 实际宽度:







Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn