Find services - Debt Consolidation - Kamala Harris - Self Improvement Articles Directory - Reference And Education Articles

PDA

View Full Version : problem with iframe: can´t access parent document


aleiderman
Aug 27th 2008, 3:02 pm
I have a bookmarklet that opens an frame in any web page. The iFrame is opened from a parent js document, which also has a method to close it up. My problem is that the close method can only be accessed from the window, but not the iframe.

The question is:
How do I access from the iframe the js methods of the parent document, to the point, how do close the iframe?

xlcho
Aug 27th 2008, 11:29 pm
Inside the iframe you have a 'parent' object which is the window. This means that if the iframe has an id 'myiframe' you can access the window using:
document.getElementById('myiframe').parent
I don't know how you wanna 'close' the iframe but i guess removing it will do the job. You can use something like that (presuming it still has the id 'myiframe'):
document.body.removeChild(document.getElementById('myiframe'));
or the long way to do the same...
document.getElementById('myiframe').parent.removeChild(document.getElementById('myiframe'));