Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-11-2002, 07:53 PM   PM User | #1
valeria_vi
New Coder

 
Join Date: Jun 2002
Location: the windy city
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
valeria_vi is an unknown quantity at this point
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
valeria_vi is offline   Reply With Quote
Old 07-11-2002, 08:06 PM   PM User | #2
joh6nn
wei wu wei


 
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
joh6nn is an unknown quantity at this point
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.
joh6nn is offline   Reply With Quote
Old 07-11-2002, 08:58 PM   PM User | #3
valeria_vi
New Coder

 
Join Date: Jun 2002
Location: the windy city
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
valeria_vi is an unknown quantity at this point
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
valeria_vi is offline   Reply With Quote
Old 07-11-2002, 09:05 PM   PM User | #4
joh6nn
wei wu wei


 
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
joh6nn is an unknown quantity at this point
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.
joh6nn is offline   Reply With Quote
Old 07-11-2002, 09:14 PM   PM User | #5
valeria_vi
New Coder

 
Join Date: Jun 2002
Location: the windy city
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
valeria_vi is an unknown quantity at this point
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
valeria_vi is offline   Reply With Quote
Old 07-11-2002, 09:21 PM   PM User | #6
joh6nn
wei wu wei


 
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
joh6nn is an unknown quantity at this point
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.
joh6nn is offline   Reply With Quote
Old 07-12-2002, 02:51 PM   PM User | #7
valeria_vi
New Coder

 
Join Date: Jun 2002
Location: the windy city
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
valeria_vi is an unknown quantity at this point
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
valeria_vi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:09 AM.


Advertisement
Log in to turn off these ads.