views:

114

answers:

3

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: iframe and container page are in different domains.

+2  A: 

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.

meder
so how this bookmarklet is doing it? http://www.kaboodle.com/zd/setup/setuphelp-firefox.html#kabbookmark
Amr ElGarhy
Doesn't the bookmarklet execute script code on the document directly instead of creating iframes? Meaning it's not subject to cross-domain policy issues.
meder
nope, i checked, its creating iframes
Amr ElGarhy
Can you paste where it's creating frames? Are you sure it's not just setting the `src` of a `script` element?
meder
yes and this script create an iframe called kabIframeId to hold pages
Amr ElGarhy
Can you paste the iframe creating code from the script?
meder
i didn't find, but how they are creating and adding this iframe to the page? :(
Amr ElGarhy
How are you sure it's an iframe? Are you inspecting it? If so provide a screenshot of said iframe code which it creates?
meder
screenshot: http://farm5.static.flickr.com/4072/4697011710_e5379dc6b8_b.jpg
Amr ElGarhy
MM, the bookmarklet doesnt seem to do that for me. Do you have to have an account in order for it to do that?
meder
regardless how they are adding this iframe, i got my answer from this http://stackoverflow.com/questions/2182027/close-iframe-cross-domain/2182058#2182058 please add this link to your answer to be a complete answer for my need, thanks a lot for your effort.
Amr ElGarhy
I think it'd be better if you answered yourself since you found it. Good find.
meder
ok, i will, thanks
Amr ElGarhy
A: 

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

Aaron Harun
+2  A: 

Beside @meder answer and his comments http://stackoverflow.com/questions/3033128/how-to-remove-iframe-from-parent-page-using-a-function-inside-the-iframe/3033152#3033152,

i found this answer http://stackoverflow.com/questions/2182027/close-iframe-cross-domain/2182058#2182058 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 :(

Amr ElGarhy