views:

3098

answers:

3

I have a site that displays other sites through an iframe on certain pages. It does this in order to display a toolbar that is relevant to the reader (like Facebook and Owly does). However, when the user chooses to leave the original site I want the bar to go away. As you might gather, I don't control the sites in the iframe, and they're on another domain than the iframing page.

I tried target="_parent" on the <iframe>, no luck. Then I tried various scripting solutions, but they all fail due to the same domain restriction. My last try was to have a timeout check for changes in the iframe URL, but iframe.contentWindow.location.href is restricted when page is on another domain (unlike the object iframe.contentWindow.location which I found a bit weird).

Any solutions to this problem? I know iframes aren't the hottest thing around, but they do the job in this case.

A: 

Try target=_top That should open the page in the full body of the window.

MystikSpiral
Christian said "I don't control the sites in the iframe", so how could he add that?
David Dorward
You said you had tried target=_parent, so forgive me. You could try embedding the HTML base tag (<base target=_top />). It goes in the head of the doc so you would have to intercept the HTML and add it using Javascript for each iFrame doc.
MystikSpiral
He said the HTML is on a different domain. It can't be intercepted with JS.
David Dorward
+1  A: 

No solutions.

The only way to get a link to open in the top frame is to have access to the link itself. As you observed, the same origin policy prevents JS from outside the frame accessing it.

David Dorward
A: 

Does onunload work with the iframe?

<iframe onunload="removeToolbar()" ... />
DreadPirateShawn
Maybe, maybe not. The point is moot since you still can't find out what the URL in the frame is, so you can't copy it to the top frame's location.
David Dorward
......................dammit.
DreadPirateShawn