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

Find container DIV ID/Name from loaded iFrame page

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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>

Jul 23 '05 #2

P: n/a
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[i].myID == myID) {
var div = "div"+parent.frames[i].name.substr(6);
parent.gsbTrace("Test1 in "+parent.frames[i].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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.