背景:
新增table tr多了之后原有的页面大小将不能展示所有信息,因此需要进行页面高度修改
实现:
这里囊是通过页面定时执行器去执行的,一秒一次实现;
function scrollHeight() {
var bodyHeight = $('body').height();
var parentIframe = parent.document.getElementById("MainWorkArea");//MainWorkArea页面id
var iframeHeight = $(parentIframe).attr("height");
if (iframeHeight <= bodyHeight) {
$(parentIframe).attr("height", bodyHeight + 50);
}
}
//定时执行器
setInterval(function () {
scrollHeight();
}, 1000);
当然也可以放到增加行的方法后面
var parentHeight = parent.document.getElementById("MainWorkArea").height;
parent.document.getElementById("MainWorkArea").height = parseInt(parentHeight)+50;
其它拓展:
1,获取屏幕的高度和宽度(屏幕分辨率):
window.screen.height
window.screen.width2,
获取屏幕工作区域的高度和宽度(去掉状态栏):
window.screen.availHeight
window.screen.availWidth
3,网页全文的高度和宽度:
document.body.scrollHeight
document.body.scrollWidth
4,滚动条卷上去的高度和向右卷的宽度:
document.body.scrollTop
document.body.scrollLeft
5,网页可见区域的高度和宽度(不加边线):
document.body.clientHeight
document.body.clientWidth
6,网页可见区域的高度和宽度(加边线):
document.body.offsetHeight
document.body.offsetWidth
7 获取窗口宽度
if (window.innerWidth)
winWidth = window.innerWidth;
else if ((document.body) && (document.body.clientWidth))
winWidth = document.body.clientWidth;
8 获取窗口高度
if (window.innerHeight)
winHeight = window.innerHeight;
else if ((document.body) && (document.body.clientHeight))
winHeight = document.body.clientHeight;
9 通过深入 Document 内部对 body 进行检测,获取窗口大小
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}