I have a page with a large iframe that contains a majority of the content. The user interacts with the website by clicking around within the iframe. The functionality I'm trying to build is: When a user navigates away from my site, I do them a favor and bust out of the iframe.

The iframe has an onload event which is fired every time a new page is loaded, cross-domain or not.

<iframe id="testframe" src="http://mysite.com" onload="testframe_loaded()"></iframe>

Each time the event is fired, I'm looking for some way to:

A) Detect when the user navigates to a different domain

B) Bust out of the iframe.

I suspect that B isn't possible, since browsers don't give access to

document.getElementById("testframe").contentDocument.location.href

when the iframe is cross-domain. I'm also not sure whether or not A is possible.

If anybody has ideas as to how to accomplish this, or is positive that it can't be done, I'd appreciate the advice.

Thanks

Edit
Report