title: Changing window.location with relative url using its own context
body: <p><strong>The problem</strong></p>
  
  <p>In my application I have a parent page which contains an iframe to a child page in a subdirectory.</p>
  
  <blockquote>
    <p>parent.html<br />
    subdir/child.html<br /></p>
  </blockquote>
  
  <p>From within the child page, I would like to set the location of the parent page using a relative url ("targetPage.html"), <em>relative to the parent</em>.</p>
  
  <blockquote>
    <p>parent.html<br />
    targetPage.html (<strong>correct</strong> target)<br />
    subdir/child.html (source of action)<br />
    subdir/targetPage.html (<strong>incorrect</strong>)</p>
  </blockquote>
  
  <p>From within the child, I can say:</p>
  
  <pre><code>window.parent.location = "targetPage.html";
  </code></pre>
  
  <p>...but of course, that (incorrectly) navigates the parent page to "subdir/targetPage.html", because the code is running in the context of the child.</p>
  
  <p>Calling code in the parent doesn't help:</p>
  
  <pre><code>window.parent.myFunctionToNavigateToTarget(); // defined in parent to navigate to "targetPage.html"
  </code></pre>
  
  <p>... has the same effect, as the parent's function is being run in the context of the child.</p>
  
  <p><strong>The Question</strong></p>
  
  <p>Is there an elegant way to set the location of another window using a relative URL, in such a way that it's interpretted relative to that window?</p>