Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get frame's height

Status
Not open for further replies.

papageno

Technical User
Dec 25, 2004
24
0
0
ES
In the following code, what should go in place of "¿?" to obtain the height of one (any) of the frames?

Code:
<head>
...
  <script language="javascript">
     var frameheight = ¿?
  </script>
</head>
<frameset rows="30,*,30">
  <frameset cols="30,*,60,*,30">
    <frame name="top1" />
    <frame name="top2" />
    <frame name="top3" />
    <frame name="top4" />
    <frame name="top5" />
  </frameset>
  <frameset cols="30,*,60,*,30">
    <frame name="middle1" />
    <frame name="middle2" />
    <frame name="middle3" />
    <frame name="middle4" />
    <frame name="middle5" />
  </frameset>
  <frameset cols="30,*,60,*,30">
    <frame name="bottom1" />
    <frame name="bottom2" />
    <frame name="bottom3" />
    <frame name="bottom4" />
    <frame name="bottom5" />
  </frameset>
</frameset>
 
I think this would work

Code:
Height = document.body.scrollHeight
 
That would be the height of the top-most frame i.e. the browser's window, wouldn't it?
 
Do you need this to work in all browsers??

I have something that will work in IE6 at the least.

It won't work in FF, and I'm not sure about IE7.

[monkey][snake] <.
 
This works in IE6:

Code:
var fr = top.frames[5]
if (fr.window.innerHeight) {
   height = fr.window.innerHeight
} else if (fr.document.body.clientHeight) {
   height = fr.document.body.clientHeight
}

However, this seems to be the height of the document, not the height of the frame.
 
In IE6, this will list the heights of each frame on the onload.
Code:
<script type="text/javascript">
   function doAlert() {
      var framesArray = window.parent.frames;
      var framesArrayLength = framesArray.length;
      for (a = 0; a < framesArrayLength; a++) {
         alert(framesArray[a].document.getElementsByTagName("body")[0].offsetHeight);
      }   
   }   
</script>
</head>
<frameset rows="30,*,30" onload="doAlert()">
  <frameset cols="30,*,60,*,30">
    <frame src="test2.html" name="top1" />
    <frame name="top2" />
    <frame name="top3" />
    <frame name="top4" />
    <frame name="top5" />
  </frameset>
  <frameset cols="30,*,60,*,30">
    <frame name="middle1" />
    <frame name="middle2" />
    <frame name="middle3" />
    <frame name="middle4" />
    <frame name="middle5" />
  </frameset>
  <frameset cols="30,*,60,*,30">
    <frame name="bottom1" />
    <frame name="bottom2" />
    <frame name="bottom3" />
    <frame name="bottom4" />
    <frame name="bottom5" />
  </frameset>
</frameset>
</html>

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top