Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iFrame try to reach a parent iFrame with Javascript

Status
Not open for further replies.

tiger311

Programmer
Sep 22, 2011
3
DE
Hello,
I have a .html link like this:

<a href="#" onclick="return popup('myPage.html');">Link here</a>

I have two frame on my page:

<frameset rows="90%,10%" border="yes" frameborder="1">
<frame name="frame1" src="Content.html"/>
<frame name="frame2" src="Footer.html"/>
</frameset>

In the "frame1" I have that link and with this script I try to reach the frame2 to create a new frame into:

<script type="text/javascript">
function popup(url) {
var runform = parent.frame2.getElementsByTagName("body")[0];
var newform = parent.frame2.createElement("iframe");

newform.setAttribute("src",url);
newform.setAttribute("allowTransparency","true");
newform.setAttribute("width","100%");
newform.setAttribute("height","30");
newform.setAttribute("scrolling","No");
runform.appendChild(newform);
return false;
}
</script>

When I execute this script I get this failure:
"Object doesnt support this property or method"
Can please somebody tell me what I'm doing wrong?
 
Hi

Tried to debug it ? By adding [tt]alert[teal]([/teal]parent[teal].[/teal]frame2[teal])[/teal][/tt] or [tt]console[teal].[/teal]log[teal]([/teal]parent[teal].[/teal]frame2[teal])[/teal][/tt] at the beginning of the popup() function you can easily find out that parent.frame2 is a [tt]Window[/tt] object. [tt]getElementsByTagName()[/tt] being a DOM method is available only on document nodes. So use [tt]parent[teal].[/teal]frame2[teal].[/teal]document[teal].[/teal]getElementsByTagName[teal]([/teal][green]"body"[/green][teal])[[/teal][purple]0[/purple][teal]][/teal][/tt] , or even better [tt]parent[teal].[/teal]frame2[teal].[/teal]document[teal].[/teal]body[/tt] .

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top