Find container DIV ID/Name from loaded iFrame page

G

gsb

Dynamically, I create a container DIV with an iFrame inside.
When the iFrame content page is loaded, I would like to determine the ID,
name DIV object reference of the "container" DIV with an onload javascript
function.

Is it possible? ...and if so, how would I do this.

Thanks,

gsb
 
E

eric

gsb,

A simple way to do what I think you want to do would be this. I
created two simple html files. One called testme.htm and one called
some.htm. Here are the two files. If you view testme.htm in your
browser you will see the name of the div in the iframe. I think this
is what you want.:

testeme.htm
<script type="text/javascript">

xyz="abc

document.write ('<div name="' + xyz + '"><iframe
src=some.htm></iframe></div>')

</script>

Testing...testing

some.htm
<script type="text/javascript">
document.write (top.xyz)
</script>
 
G

gsb

So here is what I did.

I index my 'Container-DIV/iFrame' so even though random in creation/use they
are indexed and related, like:
diviframe_1 is the container for iframeiframe_1 and 2, 3 and ...so on.


Now on the page loaded into the iframe I can add:

----------------------------------------------------------------------------
----
if(parent!=self) {
function findSelf() {
for(i=0; i<parent.frames.length; i++) {
if(parent.frames.myID == myID) {
var div = "div"+parent.frames.name.substr(6);
parent.gsbTrace("Test1 in "+parent.frames.name+" -
"+div+" "+myID);
return;
}
}
setTimeout("checkState()",2000);
};
var myID = Math.random();
window.onload=findSelf;
}
----------------------------------------------------------------------------
----

....and get:
Test2 in iframeiframe_2 - diviframe_2 0.5735005001792628
Test1 in iframeiframe_3 - diviframe_3 0.848803284388365
Test3 in iframeiframe_2 - diviframe_2 0.9736412219206069
Test2 in iframeiframe_3 - diviframe_3 0.4381383761253834
Test2 in iframeiframe_1 - diviframe_1 0.7846607844195743

So Problem solved, I think.

Thanks for you thoughts and time.

gsb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top