Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm trying to remove the frame from within the frame itself. Say my main page has an iframe (id main). Now from within the main frame, on a button click I want to be able to removeChild of the iframe... So close that window, but now the whole page itself... How can I reference the window?
Thank you

OK, I *think* I understand your question. Using a "main" page with a "main" Iframe kind of confused the issue.
Anyway, the way that I understand it, you want to have a link within an Iframe which will load that Iframe into the parent window, correct?
You can do that like this (where iframe.htm is the HTML file for the Iframe content.) Replaced <> with [] for posting purposes:
[a href="#" onclick="parent.location='iframe.htm';"]Link[/a]
Michael J

No, I don't want to change the contents of the 'main' iframe, but rather remove it as though it were no longer there.... for example
document.body.removeChild(document.getElementById('main'))... Something like that.. but I can't get the hierarchy to be able to reference the main frame...
To re-iterate, I have an .hta which I have created an iframe (id main), now inside the iframe there is another page that I want to be able to collapse (remove) the iframe from the .hta doc by using the removeChild option...

Ok, let me rephrase what I think you mean now. You want a link within the iframe that, when clicked, will remove the iframe from the parent document. If this is not what you mean, please link to an example or revise your explanation.
Ok, to do this you need to first enclose the iframe tags within div tags (hint: this makes the iframe a child). You could then remove the iframe directly within the iframe itself with a link like this:
[a href="#" onclick="parent.document.getElementById('divID').removeChild(this);"]Link[/a]
Or, my preference would be to create a function in the parent page and call that function from within the iframe. And, it would also be my preference to set the display property of the containing div to hidden (instead of removing the iframe) so that you could bring it back with another function.
Michael J

What's wrong with a div (or a span for that matter)?
[a href="#" onclick="parent.document.getElementById('main').style.display='none';"]Link[/a]
Doesn't remove it, per say, but it does hide it.
Michael J

had already tried that, but I keep getting an error saying that an object is required... It's as if it can't see the frame...

Well, I actually tested it before I posted it, so I know it works. Can you provide a link tot he pages or supply the code for your iframe in the parent page and the code for the link used in the iframe page?
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |