...

View Full Version : getting the parent for a document



tweakmy
06-18-2010, 12:45 PM
Dear Great Coders,

I am having some trouble to get the id of the parent of a document which is iframe1 here. As you can see it the <javascript> is residing in the javascript section. Do mind giving me some ideas?

Yes, I know. I can insert the javascript on the top, but believe me i cant for some purpose because I am intergrating many other codes into it.

<html>
<iframe id="iframe1">
<html>
<head>
<javascript>
</head>
<body>
</body>
</html>
</iframe>

</html>

coothead
06-18-2010, 01:35 PM
Hi there tweakmy,

and a warm welcome to these forums. ;)

Try...



<script type="text/javascript">

function init() {
if(parent.document.getElementsByTagName('iframe')[0]!=undefined) {
alert(parent.document.getElementsByTagName('iframe')[0].id);
}
}
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
}
}
</script>

coothead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum