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

A question on offsetHeight.

dmjpro
100+
P: 2,476
Have a look at my JavaScript code...
Expand|Select|Wrap|Line Numbers
  1. function resizeFrameToFitScreen(){
  2.             var outerFrameSet = window.parent.document.getElementById('outerFrameSet');
  3.             alert(parent.document.body.offsetHeight);
  4.             alert(document.body.offsetHeight);
  5.             var top_frame_percentage = Math.round((100/parent.document.body.offsetHeight)*(document.body.offsetHeight+40));
  6.             outerFrameSet.rows = top_frame_percentage+'%,'+(100-(top_frame_percentage+30))+'%,30%';
  7.  
  8.             window.parent._top_frame_percentage = top_frame_percentage;
  9.         }
  10.  
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.offsetHeight 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 ?
Sep 29 '08 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 392
If top_frame_percentage 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.


Expand|Select|Wrap|Line Numbers
  1.  
  2.     var top_frame_percentage = (  document.body.offsetHeight / parent.document.body.offsetHeight  )* 100;
  3.  
  4.     top_frame_percentage =  Math.round( top_frame_percentage );
  5.  
  6.  
Sep 29 '08 #2

dmjpro
100+
P: 2,476
If top_frame_percentage 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.


Expand|Select|Wrap|Line Numbers
  1.  
  2.     var top_frame_percentage = (  document.body.offsetHeight / parent.document.body.offsetHeight  )* 100;
  3.  
  4.     top_frame_percentage =  Math.round( top_frame_percentage );
  5.  
  6.  
Is it not the same as ...
(100/parent.document.body.offsetHeight)*document.body.o ffsetHeight
?

Debasis Jana
Sep 29 '08 #3

Post your reply

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