js跳转页面并跳转iframe

JavaScript09

js跳转页面并跳转iframe,第1张

主页面的js 先定义点击后要转的页面,例如:

function test2(){

ifr1.location.href ="2.html"// ifr1 是指主页面下的iframe id.

}

然后某子子子页面

function testclick(){

top.test2()

//window.location.href ="test.html"

}

button 的 onclick ="testclick()", 至于5秒的定义可以自己找一下资料自行解决.

在子页中加脚本检查当前URL是否就是顶层窗口对象的URL,如果一致,则说明当前页不在框架中,跳转到框架页即可.

if(location.href==top.location.href)top.location.href='框架页URL'

如果框架页中子页面可能是多个页的话,可以通过参数传递,并在框架页中解析参数,将子框架定向到指定的子页面.

这个这样可以实现.

在button中添加处理方法就可以了

<input

type="button"

onclick=p()>

一个可能的写法可以是:

function

p(){

var

o=window.open("1.html")

o.frames["iframe1"].location="2.html"

}