js跳转页面并跳转iframe

JavaScript014

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秒的定义可以自己找一下资料自行解决.

首先iframe中的页面应该与父页面是同域页面,否则跨域的话js无法控制iframe中的内容。

如果父页面与框架中的页面时同域的,可以通过改变a标签的href属性来实现:

1

<a href="javascript:return false" onclick="window.open('http://zhidao.baidu.com/','_self')" target="_blank">猛戳这里</a>

这样实际是把原来链接的作用取消,然后给a标签绑定js的window.open方法打开页面,target也就不起作用了。