首頁  >  文章  >  web前端  >  javascript獲得網頁視窗實際大小的範例程式碼_javascript技巧

javascript獲得網頁視窗實際大小的範例程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:22:22964瀏覽

javascript程式碼:

複製程式碼程式碼如下:

function get_page_size() 🎜>var re = {};
if (document.documentElement && document.documentElement.clientHeight)
{
var doc = document.documentElement;
re.width = (doc.width =doc. .scrollWidth)?doc.clientWidth-1:doc.scrollWidth;
re.height = (doc.clientHeight>doc.scrollHeight)?doc.clientHeight:doc.scrollHeight;
}
else
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;
}
返回re;
}
904 瀏覽了3 則留言

程式碼
實例
🎜>複製代碼 代碼如下:




>
取得視窗大小

function getPageSize()
{
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.in .scrollWidth)?window.innerWidth:doc.scrollWidth;
re.height = (window.innerHeight>doc.scrollHeight)?window.innerHeight:doc.scrollHeight;
}
//結果輸出至兩個文字框
document.form1.availHeight.value= re.width;
document.form1.availWidth.value= re.height;
返回重新;
}
腳本>>
頭>


瀏覽器視窗的實際高度:


>
瀏覽器視窗的實際寬度:


>
表格>

getPageSize();
window.onresize=getPageSize;
腳本>
身體>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn