title: Detect when iframe is cross-domain, then bust out of it
body: <p>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.</p>
  
  <p>The iframe has an onload event which is fired every time a new page is loaded, cross-domain or not.</p>
  
  <pre><code>&lt;iframe id="testframe" src="http://mysite.com" onload="testframe_loaded()"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>Each time the event is fired, I'm looking for some way to:</p>
  
  <p><strong>A</strong>) Detect when the user navigates to a different domain</p>
  
  <p><strong>B</strong>) Bust out of the iframe.</p>
  
  <p>I suspect that B isn't possible, since browsers don't give access to</p>
  
  <pre><code>document.getElementById("testframe").contentDocument.location.href
  </code></pre>
  
  <p>when the iframe is cross-domain. I'm also not sure whether or not A is possible.</p>
  
  <p>If anybody has ideas as to how to accomplish this, or is positive that it can't be done, I'd appreciate the advice.</p>
  
  <p>Thanks</p>