Accessing properties of parent iframes from embedding children

towel_rack
towel_rack used Ask the Experts™
on
Hope someone can help, I'm running out of hair to pull out!

I have a JavaScript/ASP application that is using Inline Frames to dymanically create a folder/sub-folder directory view for a user. The way I want it to work is like:

<a href="GetSubDir.asp?Level=0">Top Level</a>
<iframe id=">
  <a href="GetSubDir.asp?Level=1">folder1
  <a href="GetSubDir.asp?Level=1">folder2
  <iframe>
    <a href="GetSubDir.asp?Level=2">folder1_1
    <a href="GetSubDir.asp?Level=2">folder1_2
    <iframe>
      <a href="GetSubDir.asp?Level=3">folder 1_1_1
      <a href="GetSubDir.asp?Level=3">folder 1_1_2
    </iframe>
  </iframe>
</iframe>

I have all the JavaScript code and ASP working perfectly. What I can't seem to do is access the properties of the iframe at level 0 from JavaScript in iframe at level 1 and recursively access the properties of the iframe at level 1 from JavaScript in iframe at level 2.

At any stage I can use top.function() that has the relevent code block to access the properties of the top most iframe from any other iframe. But what I would like to happen is have a way thay I can pass a level 1_1_2 to a function that can chnage the properties if the iframe 1_1.

Has anyone got an idea of how to do this?

Thanks
Towel_rack
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
From within any iframe, parent refers to the container of that  iframe.

So, if you want to access a variable  in level2 from level3, you could say parent.varName in a funciton in level3.

Author

Commented:
I have tried this with varying success. I did find that I could obtain the object name with alert(parent.iframe1.name). However I was unable to access any of the attributes such as parent.iframe.style.height = 20 or alert(parent.iframe.style.height)nor could I access the frame by a named passed as a varible in a function:

function go(iframe_id){
   parent.getElementById(iframe_id).style.height = 20;
}

<SCRIPT>
  go('iframe1');
</SCRIPT>

I think I am using the wrong calls, or it needs to be thrown as an object or something.

Author

Commented:
gsatsan,

Thanks for the ideas. I have what I need for now.

  function Resize(maxheight, iframe_id)
   {

     parent.document.all(iframe_id).style.height = maxheight

  }

Is what worked. Thanks again.
Michel PlungjanIT Expert
Top Expert 2009

Commented:
parent.document.getElementById(iframe_id).style.height = 20;

would work too and also in mozilla/ns6

you forgot the document

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial