Redirect out of frame page to specific frame in index.htm

后端 未结 1 549
小蘑菇
小蘑菇 2021-01-27 17:52

I am using frames on index.html file. On every page of the frame I have a code which checks if page is in frame, and if not, then redirect to index.html.

Now. I want to

相关标签:
1条回答
  • 2021-01-27 18:31

    You need to make the code in the subpages append their name to the 'index.html', e.g.

    if (top.location == self.location) {
        top.location = 'index.html?' + location.href;
    }
    

    ...and put another Javascript on the index.html page which checks for the part after the question mark, e.g.:

    <script type="text/javascript">
    window.onload = function() {
      //check if a query string is given
      if (location.search && location.search.length > 1
           && location.search.charAt(0) == "?") {
    
          //load the URL to the frame
          window.frames["myframe"].location.href = location.search.substring(1);
      }
    }
    </script>
    

    By the way, you need to give your target frame a name like this:

    <frameset ...
        <frame name="myframe" ...
    
    0 讨论(0)
提交回复
热议问题