Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    the windy city
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    the windy city
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    the windy city
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #7
    New Coder
    Join Date
    Jun 2002
    Location
    the windy city
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •