By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,008 Members | 603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,008 IT Pros & Developers. It's quick & easy.

document.boby.offsetWidth getting different value.

P: 2,476
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
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Can you post the code that you're working with? You may find this page useful.
Nov 4 '08 #2

P: 2,476
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>
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. = 'absolute';
  3. = document.body.offsetWidth+'px';
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
Expert 100+
P: 427
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; 
  3.      if(IE){ window.innerHeight = parseInt(document.documentElement.clientHeight || document.body.clientHeight) ; }
  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.