有关js控制浏览器跳转页面的方式总结

JavaScript010

有关js控制浏览器跳转页面的方式总结,第1张

平常页面跳转可以使用在html中写a标签及跳转地址实现

这种方式的好处在于直观、方便,但是缺点在于页面会出现刷新的情况,可以使用禁用浏览器的默认事件来防止。

也可以使用js控制页面跳转

在html中 为某个标签添加点击事件

在js中 可以使用如下方法来跳转页面

要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码

JS跳转大概有以下几种方式:

第一种:(跳转到b.html)

<script language="javascript" type="text/javascript">

window.location.href="b.html"

</script>

第二种:(返回上一页面)

<script language="javascript">

window.history.back(-1)

</script>

第三种:

<script language="javascript">

window.navigate("b.html")

</script>

第四种:

<script language="JavaScript">

self.location=’b.html’

</script>

第五种:

<script language="javascript">

top.location=’b.html’

</script>

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

function test2(){

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

}

然后某子子子页面

function testclick(){

top.test2()

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

}

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