469,612 Members | 1,673 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

document.boby.offsetWidth getting different value.

dmjpro
2,476 2GB
I am testing the value of document.body.offsetWidth in Mozilla and IE.
IE gets the desired value but Mozilla is not getting the desired value.
Actually what happens, i want to position an element at the right most of the screen.In IE the element positioned properly whether the screen has scroll or not, but Mozilla positions the element but not at the rightmost if the screen has scroll.
Can anyone figure it out why it happens ?
Nov 4 '08 #1
3 2374
acoder
16,027 Expert Mod 8TB
Can you post the code that you're working with? You may find this page useful.
Nov 4 '08 #2
dmjpro
2,476 2GB
Can you post the code that you're working with? You may find this page useful.
Thanks for reply.. ;)
Here is my HTML code ....
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:void(0);" onclick="closeWindow('<%=request.getParameter("cal_event_type")%>')"><img alt="Cross" src="./img/cross.JPG" id="cross_image" title="Cross the window" style="height:7px;width:7px"/></a>
  2.  
I am repositioning the cross image when page gets loaded...that means during onLoad event.

Here is my JavaScript code ..
Expand|Select|Wrap|Line Numbers
  1. var cross_image_ref = document.getElementById('cross_image');
  2. cross_image_ref.style.position = 'absolute';
  3. cross_image_ref.style.left = document.body.offsetWidth+'px';
  4.  
Remember if the screen is having horizontal scroll then it does not work in Mozilla but it works expectedly in IE.
Why it differs ..please help!

By the way i solved this problem .... I know that in the page which causes the scroll bars.. i am having the width of that element and reposition the image ..
but it's not a feasible solution ..what do you think ? ..... ;)
Nov 4 '08 #3
rnd me
427 Expert 256MB
you might have better luck with a more resiliant, doctype proof assesment of the width:

Expand|Select|Wrap|Line Numbers
  1. IE=false;   //@cc_on; IE=true; 
  2.  
  3.      if(IE){ window.innerHeight = parseInt(document.documentElement.clientHeight || document.body.clientHeight) ; }
  4.  
  5.     if(IE){ window.innerWidth = parseInt(document.documentElement.clientWidth || document.body.clientWidth); }
this adds the w3 innerWidth value to IE under either quirks or strict rendering.

you can also use style.right = "2%" to hug the right side, lots of people forget about that and use 98% left instead...
Nov 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Stumped and Confused | last post: by
1 post views Thread by parksch2 | last post: by
4 posts views Thread by Captain Dondo | last post: by
5 posts views Thread by liketofindoutwhy | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.