Skip to content Skip to sidebar Skip to footer

How To Remove Iframe From Parent Page Using A Function Inside The Iframe?

I have an iframe I put on a page using a bookmarklet, I want this iframe to close itself when I navigate to a certain page inside this iframe. How to do that using JavaScript? Note

Solution 1:

As far as I know you cannot remove the element from the DOM from the iframe's container unless it's the same domain if I'm understanding you properly due to cross-domain security policies.

If this were possible you could infiltrate bank sites and all, it'd be a mess.

Solution 2:

Beside @meder answer and his comments How to remove iframe from parent page using a function inside the iframe?,

i found this answer Close iframe cross domain Which helped me too much to solve my problem.

UPDATE: I found that this solution is not working on IE, and i failed to find a solution for that :(

Solution 3:

it isn't possible due the so called 'same origin policy' ( http://en.wikipedia.org/wiki/Same_origin_policy )

if it's within the same domain you can try

jQuery('iframe-selector').remove(); // remove iframejQuery('iframe-selector').contents().empty(); // remove the iframe contentjQuery('iframe-selector').removeAttr('src'); // remove the source-attribute from the iframejQuery('iframe-selector').attr('src', 'javascript:return false;'); // remove the iframe source

Solution 4:

You can't do cross-domain scripting with Iframes.

Post a Comment for "How To Remove Iframe From Parent Page Using A Function Inside The Iframe?"