首頁 > web前端 > js教程 > 主體

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

WBOY
發布: 2016-05-16 17:22:22
原創
963 人瀏覽過

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;
腳本>
身體>

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!