Redirect page if not in frame using JQuery

Redirect page if not in frame using JQuery

Hello and thank you for reading my topic. I'd like to detect whether or not the current page that isn't the index page is in a frame, and if not, redirect to the index page and then replace a frame with the document originally trying to be accessed. Using JQuery I can detect whether or not the page is in a frame and whether or not the page is the index page just fine:

Frameset of index.html:
  1. <frameset rows="100%, 0%" frameborder="0">
  2. <frame src="content.html" name="content" noresize>
  3. <frame src="audio.html" name="audio" noresize>
  4. </frameset>

page.html, for our purposes this isolated code is loaded on every page:
  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. if ((window.top == window.self) && (top.document.location.pathname != "/index.html")) {
  4. $(location).attr("href", "/index.html");
  5. $(window.parent.frames["content"].document.location).attr("src", document.location.pathname);
  6. }
  7. });
  8. </script>

So, if the target page is opened up directly (and already isn't the index page), it will redirect to the index page successfully. However, the original document doesn't get replaced into the content frame.

Is this solution possible using JQuery?