Re: Find out the page dimensions
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Mon, 1 Dec 2008 14:31:17 -0800 (PST)
On Dec 1, 5:14 pm, Conrad Lender <crlen...@xxxxxxxxx> wrote:
On 2008-12-01 17:23, SAM wrote:
onload = function() {
var d = document.createElement('DIV');
d.style.height = document.body.offsetHeight + 'px';
d.style.width = document.body.offsetWidth + 'px';
d.style.position = 'absolute;
d.style.top = d.style..left = 0;
d.style.background = 'black';
d.title = 'click to close me';
d.onclick= function() { this.style.display='none'; };
document.body.appendChild(d);
}
Not tested !
David's right, this is neither syntactically correct, nor would it do
Except the FAQ doesn't have the exact example as he wants to cover the
document, not the viewport. Of course, the code above won't do that
either.
what the OP requires. Daniel, here's something to get you started; with
a few caveats:
- I didn't have any older browsers around for testing; the function
should probably be improved to return something useful for them.
- It uses browser sniffing. Yeah, I know. I'm going to get flamed for
this -- if anybody here knows a way to adjust the results for IE in
quirks mode with feature testing, that would be great.
See the FAQ viewport example.
- It may not work if the body has a negative margin. If you need to
handle this case, you'll have to edit the function to account for it.
- I didn't handle the height bug in Opera 9 in this example, there's a
test and workaround for that in the group FAQ.
There is? I remember talking about adding one, but I didn't know it
was changed.
That said, as far as I can see, it apperars to do the job in FF2, FF3,
IE6, IE7, Safari 3, Konqueror 3.5, and Opera 9 (if the body is higher
than the viewport).
var isMSIE;
/*@cc_on
isMSIE = true;
@*/
See what the document.documentElement.clientWidth/Height properties
are in IE quirks mode (or IE < 6.) IIRC, they are 0. In that case,
use the scrollWidth/Height properties of the body, and otherwise use
the documentElement. There are other issues related to margins (on
the body in quirks mode, documentElement in standards mode.) Best to
avoid those at the design stage.
Also, make sure the expected properties are numbers.
[snip]
.
- Follow-Ups:
- Re: Find out the page dimensions
- From: Conrad Lender
- Re: Find out the page dimensions
- References:
- Find out the page dimensions
- From: Daniel Norden
- Re: Find out the page dimensions
- From: SAM
- Re: Find out the page dimensions
- From: Conrad Lender
- Find out the page dimensions
- Prev by Date: Re: Prototype Convention?
- Next by Date: Re: speed issues traversing the DOM.
- Previous by thread: Re: Find out the page dimensions
- Next by thread: Re: Find out the page dimensions
- Index(es):
Relevant Pages
|