Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > help with document height/width

Reply
Thread Tools

help with document height/width

 
 
Adam Yee
Guest
Posts: n/a
 
      10-07-2009
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)?
 
Reply With Quote
 
 
 
 
Garrett Smith
Guest
Posts: n/a
 
      10-07-2009
Hans-Georg Michna wrote:
> On Wed, 7 Oct 2009 00:59:03 -0700 (PDT), Adam Yee wrote:
>
>> 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)?

>
> $(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.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
 
Reply With Quote
 
 
 
 
David Mark
Guest
Posts: n/a
 
      10-07-2009
On Oct 7, 1:16*pm, Hans-Georg Michna <hans-
(E-Mail Removed)> wrote:
> On Wed, 7 Oct 2009 00:59:03 -0700 (PDT), Adam Yee wrote:
> >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)?

>
> $(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.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-07-2009
Adam Yee wrote:

> 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
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
Garrett Smith
Guest
Posts: n/a
 
      10-07-2009
Thomas 'PointedEars' Lahn wrote:
> Adam Yee wrote:
>
>> 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.
>

That sounds a little condescending and inflammatory.

It could end up with you the center of negative attention, as happened
recently.

>> 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.
>


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

>> 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.


That doesn't seem very helpful. How could anyone know which manual you
are thinking of?
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-08-2009
Garrett Smith wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Adam Yee wrote:
>>> 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.
>>

> 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.

>>> 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.

>
> No, but there is a "height" property of document in a few browsers, way
> back to NS4, perhaps earlier.


And perhaps irrelevant today?

>>> 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.

>
> 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
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$(E-Mail Removed)> (2004)
 
Reply With Quote
 
Adam Yee
Guest
Posts: n/a
 
      10-09-2009
On Oct 7, 2:57*pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> Adam Yee wrote:
> > 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.
>


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.

> > 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?
>


Not right now.

> > 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.


Ok, thanks.

>
> > 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.
>


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.

> PointedEars
> --
> Anyone who slaps a 'this page is best viewed with Browser X' label on
> a Web page appears to be yearning for the bad old days, before the Web,
> when you had very little chance of reading a document written on another
> computer, another word processor, or another network. -- Tim Berners-Lee


 
Reply With Quote
 
Adam Yee
Guest
Posts: n/a
 
      10-09-2009
On Oct 8, 6:18*am, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> Garrett Smith wrote:
> > Thomas 'PointedEars' Lahn wrote:
> >> Adam Yee wrote:
> >>> 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.

>
> > That sounds a little condescending and inflammatory.

>
> 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.

> > 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.
>
>
>
> >>> 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.

>
> > No, but there is a "height" property of document in a few browsers, way
> > back to NS4, perhaps earlier.

>
> And perhaps irrelevant today?
>
> >>> 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.

>
> > 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
> --
> Danny Goodman's books are out of date and teach practices that are
> positively harmful for cross-browser scripting.
> *-- Richard Cornford, cljs, <cife6q$253$1$(E-Mail Removed)> (2004)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A HTML document can be converted to XHTML document. mike Java 2 01-14-2005 06:00 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM
DocumentBuilder.parse() returns "[#Document: null]" Document Mike Java 0 09-06-2003 03:38 AM
Help with JDOM, turn org.jdom.Document -> org.w3c.dom.Document? Wendy S Java 1 08-04-2003 11:48 PM
Xalan document() function finding wrong document root Steve Carrow Java 0 07-28-2003 02:28 AM



Advertisments