将框架外页面重定向到index.htm中的特定框架 [英] Redirect out of frame page to specific frame in index.htm

查看:89
本文介绍了将框架外页面重定向到index.htm中的特定框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在index.html文件上使用框架.在框架的每一页上,我都有一个代码,用于检查页面是否在框架中,如果不在框架中,则将其重定向到index.html.

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.

现在.我不仅要检查页面是否在框架中并重定向到index.html,还要在index.html的其中一个框架中打开页面.

Now. I want to not only check if page is in frame and redirect to index.html, but also I want to open the page in one of the frames on index.html.

到目前为止,我已经使用以下代码嵌入了JS文件:

I have embedded the JS file with this code as of right now:

if (top.location == self.location)
{
    top.location = 'index.html'
} 

您可能知道任何脚本吗?

Is there any scripts you might know of?

推荐答案

您需要使子页面中的代码将其名称附加到'index.html'上,例如

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;
}

...并在index.html页面上放置另一个Javascript,该Javascript检查问号后的部分,例如:

...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" ...

这篇关于将框架外页面重定向到index.htm中的特定框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆