c12
c12

Reputation: 9827

Closing Iframe with Javascript in IE

I'm trying to close a Iframe and the below works for every browser except for IE7 an IE8. Any suggestions for IE? The button acutally exists on the iframe itself.

<input type="submit" onclick="history.go(0)"

Upvotes: 0

Views: 3441

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074266

I don't know what "close" means with regard to an iframe other than removing it, so:

You can remove an iframe from the document using removeChild on its parent node, e.g.:

var iframe = window.parent.document.getElementById('theIframe');
iframe.parentNode.removeChild(iframe);

Live example

There I'm using an id to find the iframe element in the parent window, but obviously you have lots of choices for how to find it. Ultimately it comes down to calling removeChild.

Upvotes: 5

Related Questions