Iterate through all iframes in the document

I have a html document with code:

<body>
<iframe id="full_content_frame" src="tmpl_content1.htm" frameborder="0" width="100%">
</iframe>
<iframe id="full_content_frame" src="tmpl_content2.htm" frameborder="0" width="100%">
</iframe>
......
</body>


and in tmpl_contentX.html I have:
<body onload="resizeIframe('full_content_frame')">
.....
</body>



and main goal is to determine height of each frame and adjust iframe.height that all frames would be one by one vertically.
I am looking for any possibility to achieve that and one technique was successfull:

function resizeIframe(id)
{
       parent.document.getElementById(id).style.height = (this.document.body.scrollHeight) + "px";
}

But it will correctly adjust only the first frame. How I can apply such method for all frames in parent document?
Or is there another flexible method to adjust numerous ifames?
NeolitenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
First, id's should be unique. You cannot have two tags with the same id.

<script type="text/javascript">
  function doIt() {
    var d = document.getElementsByTagName('iframe');
    for(var i = 0; i < d.length; i++) {
      d[i].style.height = (this.document.body.scrollHeight/d.length) + "px";
    }
  }
</script>
<body>
  <iframe id="full_content_frame" src="tmpl_content1.htm" frameborder="0" width="100%">
  </iframe>
  <iframe id="full_content_frame" src="tmpl_content2.htm" frameborder="0" width="100%">
  </iframe>
  <input type="button" onclick="doIt();" value="doIt();" />
</body>

-r-
NeolitenAuthor Commented:
Thanks, but how to do it automatically?
Becides, height of all frames would be the same.
RoonaanCommented:
Below script works in firefox and internet explorer 6 but has not been tested on opera, netscape, internet explorer 5.

-r-

<html>
  <head>
    <script type="text/javascript">
      function windowHeight()
      {
        if(window.innerHeight)
          x = window.innerHeight
        else if(document.body.clientHeight)
          x = document.body.clientHeight;
        else
          x = screen.height;
        return x;
      }
     
      function setSize() {
        var d = document.getElementsByTagName('iframe');
        var h = windowHeight() / d.length;
        for(var i = 0; i < d.length; i++) {
          d[i].style.height = (h) + "px";
        }
      }
    </script>
  </head>
  <body onload="setSize();" onresize="setSize();" style="margin:0;padding:0;">
    <iframe id="full_content_frame" src="tmpl_content1.htm" frameborder="0" width="100%">
    </iframe>
    <iframe id="full_content_frame" src="tmpl_content2.htm" frameborder="0" width="100%">
    </iframe>
  </body>
</html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZvonkoSystems architectCommented:
Check this:

<body>
<iframe id="full_content_frame" src="tmpl_content1.htm" frameborder="0" width="100%">
</iframe>
<iframe id="full_content_frame" src="tmpl_content2.htm" frameborder="0" width="100%">
</iframe>
<iframe id="full_content_frame" src="tmpl_content3.htm" frameborder="0" width="100%">
</iframe>
<iframe id="full_content_frame" src="tmpl_content4.htm" frameborder="0" width="100%">
</iframe>
<script>
var frm = window.frames;
var pct = parseInt(1/frm.length*100)+"%";
alert(pct)
for(var i=0;i<frm.length;i++){
  frm[i].frameElement.style.height=pct;
}
</script>
</body>

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.