title: Why can't an iframe set its parent's location.hash?
body: <p>I have a window containing an iframe, containing an iframe, like so:</p>
  
  <pre><code>+---------------+
  |      Top      |
  | +-----------+ |
  | |   Middle  | |
  | | +-------+ | |
  | | | Inner | | |
  | | +-------+ | |
  | +-----------+ |
  +---------------+
  </code></pre>
  
  <p>Top and Middle are on the same domain, but Inner is on a different domain.  I need Inner to communicate with Top.  The only way I know of to do this which is supported in IE7 (which I need to support) is to change the hash of the window's location.  However, I don't want the information to be flickering in the location bar, so I've introduced the Middle iframe.</p>
  
  <p>I want Inner to change Middle's hash.  Middle will read its hash and inform Top, whom it has permission to speak to directly.</p>
  
  <p><strong>However</strong>, in Firefox 3, I've been unable to write to Middle's hash from Inner.  No error is raised, but the hash appears unchanged.  Writing to its <code>location.href</code> raises a permissions error.</p>
  
  <p>Top can write to Middle's hash, however, and Middle can write to Inner's hash, and Top can write to Inner's hash, and Inner and Middle can both write to Top's hash, so the <em>only ordered pair</em> that doesn't work is the one I want!  (I've been working on this for a while.)</p>
  
  <p>I've reproduced this in a minimal test case.  At first, I served all three pages from the same domain.  When I put Inner on a different domain, I get the problematic behavior.  When I put Middle on the second domain, everyone can write to everyone again.</p>
  
  <p>Why can't Inner write to Middle's hash?</p>
  
  <hr>
  
  <p><strong>Addendum</strong>: Many people have suggested that this shouldn't be possible because of the same-origin policy.  This is exactly the policy I am trying to get around.  This exact case--setting (but not reading) another window's location--is supposed to be possible across domains.  I haven't found browser documentation to this effect, but I have found many articles and demos.  This is essentially the precursor to HTML 5's <code>postMessage()</code>.</p>
  
  <p>Ref: <a href="http://softwareas.com/cross-domain-communication-with-iframes" rel="noreferrer">http://softwareas.com/cross-domain-communication-with-iframes</a></p>