help with document height/width

A

Adam Yee

I can't seem to get IE8 to create a working clientHeight or
clientWidth. I've tried a few combinations with varied results, but
nothing that works all the way like in FF.

I've tried these (probably a couple others also):
doc_width = document.documentElement.clientWidth;
doc_height = document.documentElement.clientHeight;

doc_width = document.body.offsetWidth + document.body.offsetLeft;
doc_height = document.body.offsetHeight + document.body.offsetTop;

var doc_height = (document.height !== undefined) ? document.height :
document.body.offsetHeight;
var doc_width = (document.width !== undefined) ? document.width :
document.body.offsetWidth;

Can anyone help me out with correct object creation for height and
width (for IE)?
 
G

Garrett Smith

Hans-Georg Michna said:
$(document).height()
$(document).width()

<grin duck run />

From beyond the fence: To be honest, that requires jQuery, which
promises to shield you from browser dependencies and is not pure
JavaScript. Purists don't like it.

Why label those who try to understand how to solve problems? Why not
just learn how to solve them instead of putting others down?

Can you post the code you mentioned? Can you provide an explanation of it?

I believe that would lead to much more worthwhile and productive discussion.
http://docs.jquery.com/CSS/height

I mention it only because it is simple and easy. But I'm sure
somebody else will come forward with a genuine pure-JavaScript
solution.
You could try the reading the FAQ to see a solution.

Out of context, it would seem to mean something only in Mozilla's
JavaScript language, as what could be used in a js shell (no host object).

But the way you are using it, I get the sense that it means, to you,
The absence of an abstraction that you do not understand.
 
D

David Mark

$(document).height()
$(document).width()

And if you look behind the scenes, you'll find a poor man's version of
the one in My Library (soon to be in Dojo).

We just discussed this, going all the way back to IE5 and Safari 2.
 
T

Thomas 'PointedEars' Lahn

Adam said:
I can't seem to get IE8 to create a working clientHeight or
clientWidth. I've tried a few combinations with varied results, but
nothing that works all the way like in FF.

You don't seem to have powered-up your brain before trying at all, so the
results are unsurprising.
I've tried these (probably a couple others also):
doc_width = document.documentElement.clientWidth;
doc_height = document.documentElement.clientHeight;

Works in Standards Compliance Mode.
doc_width = document.body.offsetWidth + document.body.offsetLeft;
doc_height = document.body.offsetHeight + document.body.offsetTop;

Care to explain what the computed left/top coordinates would have to do with
the width and height of an element?
var doc_height = (document.height !== undefined) ? document.height :
document.body.offsetHeight;

Document objects have no height as they have no graphical representation.
var doc_width = (document.width !== undefined) ? document.width :
document.body.offsetWidth;

Neither do they have a width.
Can anyone help me out with correct object creation for height and
width (for IE)?

The objects are there, they do not need to be created. RTFM.


PointedEars
 
G

Garrett Smith

Thomas said:
You don't seem to have powered-up your brain before trying at all, so the
results are unsurprising.
That sounds a little condescending and inflammatory.

It could end up with you the center of negative attention, as happened
recently.
Works in Standards Compliance Mode.


Care to explain what the computed left/top coordinates would have to do with
the width and height of an element?


Document objects have no height as they have no graphical representation.

No, but there is a "height" property of document in a few browsers, way
back to NS4, perhaps earlier.
Neither do they have a width.


The objects are there, they do not need to be created. RTFM.

That doesn't seem very helpful. How could anyone know which manual you
are thinking of?
 
T

Thomas 'PointedEars' Lahn

Garrett said:
That sounds a little condescending and inflammatory.

It's the hard truth. The OP hasn't done *any* homework before, just copy-
and-pray.
It could end up with you the center of negative attention, as happened
recently.

This is not a help desk, so I don't particularly care what oversensitive
people might think of my postings.
No, but there is a "height" property of document in a few browsers, way
back to NS4, perhaps earlier.

And perhaps irrelevant today?
That doesn't seem very helpful.

That's too bad. They should ask for a refund.
How could anyone know which manual you are thinking of?

By reading the FAQ and following its recommendations. It is not exactly new
here.

Your posting consisted of nothing but irrelevance. And where is your
counter-suggestion to solve the OP's problem? You should read the FAQ and
adhere to what you are maintaining, otherwise you could rightfully be called
a hypocrite.


PointedEars
 
A

Adam Yee

You don't seem to have powered-up your brain before trying at all, so the
results are unsurprising.

Yes, the power switch was definitely flakey. I'm not surprised with my
results either. This is after all my very first attempt at writing a
useful piece of JS.
Works in Standards Compliance Mode.


Care to explain what the computed left/top coordinates would have to do with
the width and height of an element?

Not right now.
Document objects have no height as they have no graphical representation.


Neither do they have a width.

Ok, thanks.
The objects are there, they do not need to be created.  RTFM.

After some needed reading with the power switch on, I've gotten
through my problem. Sometimes people really do need to be told to
RTFM.
 
A

Adam Yee

It's the hard truth.  The OP hasn't done *any* homework before, just copy-
and-pray.

The homework results are:
document.body.clientHeight/Width can be used only after the <body> has
finished rendering. I was getting object required errors. My fix was
externally loading the script after the body.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top