Web Analytics Made Easy -
StatCounter document.body.clientWidth - CodingForum

Announcement

Collapse
No announcement yet.

document.body.clientWidth

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • document.body.clientWidth

    i need to find out the inner width of a browser window. i'm using window.innerWidth for ns4.x and it works fine.
    for ie i am trying to use document.body.clientWidth, but i get an error saying "document.body.clientWidth is not an object" (on a mac) or "objet expected" (on a pc). I have also tried using document.getElementById('body').clientWidth, but it would generate the same error message.
    i finally went to javascriptkit.com wherethere is a tutorial on "Using JavaScript to statically display elements" (http://javascriptkit.com/javatutors/static.shtml) and it says there to use the same expressions I am using. On page 3 of teh tutorial (http://javascriptkit.com/javatutors/static3.shtml) there is an example that actually utilizes document.body.clientWidth and it works in my browser with no error messages whatsoever. so why would teh same expression give me an error on another page? the page was working fine before document.body.clientWidth was added to it, so I know it is not an error from something above that piece of code.
    here's the script:
    Code:
    var wdth
    if (document.layers) {
    wdth = window.innerWidth
    alert(wdth)
    }
    else {
    wdth = document.body.clientWidth
    alert(wdth)
    }
    am i just not seeing something obvious???
    Goals are dreams with deadlines
    -------------------------------------
    Nimlok Trade Show Display Booth and Exhibit
    http://www.orbusinc.com

  • #2
    if i remember correctly, it's window.body.clientWidth. the link to Microsoft in my sig will tell you for sure.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      john,
      here's a piece of script from msdn:
      Center the object horizontally:
      object.style.left=(document.body.clientWidth/2) - (object.offsetWidth/2);

      doh, i really cannot think of a reson for the thing not to work!
      Goals are dreams with deadlines
      -------------------------------------
      Nimlok Trade Show Display Booth and Exhibit
      http://www.orbusinc.com

      Comment


      • #4
        are you trying to use this information before the onload event has fired?
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment


        • #5
          i have no onload events on my page.
          i am trying to use it inside a .js page wichi is linked to from the <body> of the html document.
          Goals are dreams with deadlines
          -------------------------------------
          Nimlok Trade Show Display Booth and Exhibit
          http://www.orbusinc.com

          Comment


          • #6
            i think that's your problem, then. i could be misremembering, but i think that IE throws a fit if you try access those properties, before the page has finished loading. trying moving that code into an onload event handler, if possible.

            if that doesn't solve it, then i have no idea.
            bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

            i am a loser geek, crazy with an evil streak,
            yes i do believe there is a violent thing inside of me.

            Comment


            • #7
              John!
              You were right - once moved into the onLoad - it worked!
              now i need to think how to accomodate my script with that, but i have an idea already.

              THANKS A LOT!
              Goals are dreams with deadlines
              -------------------------------------
              Nimlok Trade Show Display Booth and Exhibit
              http://www.orbusinc.com

              Comment

              Working...
              X