help with document height/width

Discussion in 'Javascript' started by Adam Yee, Oct 7, 2009.

  1. Adam Yee

    Adam Yee Guest

    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)?
     
    Adam Yee, Oct 7, 2009
    #1
    1. Advertising

  2. 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/
     
    Garrett Smith, Oct 7, 2009
    #2
    1. Advertising

  3. Adam Yee

    David Mark Guest

    On Oct 7, 1:16 pm, Hans-Georg Michna <hans-
    > 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.
     
    David Mark, Oct 7, 2009
    #3
  4. 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
     
    Thomas 'PointedEars' Lahn, Oct 7, 2009
    #4
  5. 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/
     
    Garrett Smith, Oct 7, 2009
    #5
  6. 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$> (2004)
     
    Thomas 'PointedEars' Lahn, Oct 8, 2009
    #6
  7. Adam Yee

    Adam Yee Guest

    On Oct 7, 2:57 pm, 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.
    >


    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
     
    Adam Yee, Oct 9, 2009
    #7
  8. Adam Yee

    Adam Yee Guest

    On Oct 8, 6:18 am, Thomas 'PointedEars' Lahn <>
    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$> (2004)
     
    Adam Yee, Oct 9, 2009
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lois
    Replies:
    1
    Views:
    3,403
    Ryan Stewart
    Dec 27, 2004
  2. cera
    Replies:
    1
    Views:
    1,342
    Neredbojias
    Aug 18, 2007
  3. Bernd Meier
    Replies:
    6
    Views:
    546
    GTalbot
    Jan 14, 2008
  4. Kepler
    Replies:
    12
    Views:
    367
    Richard Cornford
    Sep 20, 2004
  5. VK
    Replies:
    10
    Views:
    194
    GTalbot
    May 8, 2008
Loading...

Share This Page