Javascript 将框架外页面重定向到index.htm中的特定框架

Javascript 将框架外页面重定向到index.htm中的特定框架,javascript,html,frame,frameset,Javascript,Html,Frame,Frameset,我正在index.html文件上使用框架。在框架的每一页上,我都有一个代码来检查页面是否在框架中,如果不在框架中,则重定向到index.html 现在。我不仅想检查页面是否在框架中并重定向到index.html,还想在index.html上的一个框架中打开页面 我已经在JS文件中嵌入了以下代码: if (top.location == self.location) { top.location = 'index.html' } 是否有您可能知道的脚本?您需要使子页面中的代码将其名称附

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

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

我已经在JS文件中嵌入了以下代码:

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

是否有您可能知道的脚本?

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

if (top.location == self.location) {
    top.location = 'index.html?' + location.href;
}
…并在index.html页面上放置另一个Javascript,用于检查问号后面的部分,例如:

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

window.onload=函数(){
//检查是否给出了查询字符串
如果(location.search&&location.search.length>1
&&location.search.charAt(0)==“?”){
//将URL加载到框架中
window.frames[“myframe”].location.href=location.search.substring(1);
}
}
顺便说一下,您需要为目标帧命名如下:

<frameset ...
    <frame name="myframe" ...

我无法工作:/it会移动我,但会将地址栏中的地址更改为:
http://192.168.0.2/csharp%20projects/index.html?http://192.168.0.2/csharp%20projects/sitemap.html
from:
http://192.168.0.2/csharp%20projects/
它更改地址,告诉框架集页面应该加载哪个子页面。我想你无法避免地址的改变。这就是为什么很多人不喜欢框架集的原因。有趣的答案:;-)是的,我很乐意使用一些不仅仅是HTML和JavaScript的东西。但我正在做班级项目,我的智慧有限。但框架的积极一面是,它在许多浏览器中都受支持,使用它不会有任何实际问题。一切都很完美,直到我不得不克服重定向问题。这让我走上了正确的道路:)