document.boby.offsetWidth getting different value.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    document.boby.offsetWidth getting different value.

    I am testing the value of document.body.o ffsetWidth 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 ?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you post the code that you're working with? You may find this page useful.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by acoder
      Can you post the code that you're working with? You may find this page useful.
      Thanks for reply.. ;)
      Here is my HTML code ....
      Code:
      <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 ..
      Code:
      var cross_image_ref = document.getElementById('cross_image');
      cross_image_ref.style.position = 'absolute';
      cross_image_ref.style.left = 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 ? ..... ;)

      Comment

      • rnd me
        Recognized Expert Contributor
        • Jun 2007
        • 427

        #4
        you might have better luck with a more resiliant, doctype proof assesment of the width:

        Code:
        IE=false;   //@cc_on; IE=true; 
        
         	if(IE){ window.innerHeight = parseInt(document.documentElement.clientHeight || document.body.clientHeight) ; }
        
        	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...

        Comment

        Working...