D
Daniel Norden
Hello.
I'm trying create a DIV element that covers the whole page. To do this, I
need to find out the exact size of the current page. I've seen the very
comprehensive topic about the viewport size in the group FAQ. Is there
anything comparable for reading the size of the page, not just the
viewport?
I've tried the following function (which was adapted from the Lightbox2
script). It's supposed to return the size of my DIV..... if the page is
small, the DIV should at least cover the whole viewport. It works nicely in
IE6, IE7, Safari, Opera, but not quite in Firefox (2 and 3):
function getPageSize(){
var body = document.body;
var docEle = document.documentElement;
var doc_w, doc_h;
var vp_w, vp_h;
if (window.innerHeight && window.scrollMaxY) {
doc_w = window.innerWidth + window.scrollMaxX;
doc_h = window.innerHeight + window.scrollMaxY;
} else if (body.scrollHeight > body.offsetHeight) {
doc_w = body.scrollWidth;
doc_h = body.scrollHeight;
} else {
doc_w = body.offsetWidth;
doc_h = body.offsetHeight;
}
if (window.innerHeight) {
if (docEle && docEle.clientWidth) {
vp_w = docEle.clientWidth;
} else {
vp_w = window.innerWidth;
}
vp_h = window.innerHeight;
} else if (docEle && docEle.clientHeight) {
vp_w = docEle.clientWidth;
vp_h = docEle.clientHeight;
} else {
vp_w = body.clientWidth;
vp_h = body.clientHeight;
}
return {
height: Math.max(doc_h, vp_h),
width: Math.max(doc_w, vp_w)
};
}
In Firefox the width and height are a little too large, which makes the
scrollbars jump (if there are scrollbars). How can I avoid this? Is there a
better way to write this function?
Thanks in advance!
Dano
I'm trying create a DIV element that covers the whole page. To do this, I
need to find out the exact size of the current page. I've seen the very
comprehensive topic about the viewport size in the group FAQ. Is there
anything comparable for reading the size of the page, not just the
viewport?
I've tried the following function (which was adapted from the Lightbox2
script). It's supposed to return the size of my DIV..... if the page is
small, the DIV should at least cover the whole viewport. It works nicely in
IE6, IE7, Safari, Opera, but not quite in Firefox (2 and 3):
function getPageSize(){
var body = document.body;
var docEle = document.documentElement;
var doc_w, doc_h;
var vp_w, vp_h;
if (window.innerHeight && window.scrollMaxY) {
doc_w = window.innerWidth + window.scrollMaxX;
doc_h = window.innerHeight + window.scrollMaxY;
} else if (body.scrollHeight > body.offsetHeight) {
doc_w = body.scrollWidth;
doc_h = body.scrollHeight;
} else {
doc_w = body.offsetWidth;
doc_h = body.offsetHeight;
}
if (window.innerHeight) {
if (docEle && docEle.clientWidth) {
vp_w = docEle.clientWidth;
} else {
vp_w = window.innerWidth;
}
vp_h = window.innerHeight;
} else if (docEle && docEle.clientHeight) {
vp_w = docEle.clientWidth;
vp_h = docEle.clientHeight;
} else {
vp_w = body.clientWidth;
vp_h = body.clientHeight;
}
return {
height: Math.max(doc_h, vp_h),
width: Math.max(doc_w, vp_w)
};
}
In Firefox the width and height are a little too large, which makes the
scrollbars jump (if there are scrollbars). How can I avoid this? Is there a
better way to write this function?
Thanks in advance!
Dano