A question on offsetHeight.

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

    A question on offsetHeight.

    Have a look at my JavaScript code...
    Code:
    function resizeFrameToFitScreen(){
                var outerFrameSet = window.parent.document.getElementById('outerFrameSet');
                alert(parent.document.body.offsetHeight);
                alert(document.body.offsetHeight);
                var top_frame_percentage = Math.round((100/parent.document.body.offsetHeight)*(document.body.offsetHeight+40));
                outerFrameSet.rows = top_frame_percentage+'%,'+(100-(top_frame_percentage+30))+'%,30%';
                
                window.parent._top_frame_percentage = top_frame_percentage;
            }
    I am calling this function when a page is loaded. The page attached to a frame of a parent window. First alert shows the parent window offsetHeight, the actual one acquired by the parent window. And the second alert shows the actual height of the current window. If i don't add 40 with document.body.o ffsetHeight it would show me the scroll bars in the window, but i write this code to fit the current window according to the resolution. Where i am going wrong ?
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    If top_frame_perce ntage is in fact supposed to be a percentage of the child frame inside the parent frame then you should be dividing the child frame by the parent frame. The math should look like this.


    Code:
        var top_frame_percentage = (  document.body.offsetHeight / parent.document.body.offsetHeight  )* 100;
    
        top_frame_percentage =  Math.round( top_frame_percentage );

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by pronerd
      If top_frame_perce ntage is in fact supposed to be a percentage of the child frame inside the parent frame then you should be dividing the child frame by the parent frame. The math should look like this.


      Code:
          var top_frame_percentage = (  document.body.offsetHeight / parent.document.body.offsetHeight  )* 100;
      
          top_frame_percentage =  Math.round( top_frame_percentage );
      Is it not the same as ...
      (100/parent.document .body.offsetHei ght)*document.b ody.offsetHeigh t
      ?

      Debasis Jana

      Comment

      Working...