HTML页面刷新、跳转

时间:2023-03-08 19:27:29
HTML页面刷新、跳转

HTML方式

1、页面刷新

<!-- 5秒之后,跳转到http://www.qunar.com页面 -->
<meta http-equiv="refresh" content="5" />

2、页面跳转

<!-- 5秒之后,跳转到http://www.qunar.com -->
<meta http-equiv="refresh" content="5; url=http://www.qunar.com" />
<!-- 点击qunar跳转到http://www.qunar.com -->
<a href="http://www.qunar.com">qunar</a>

JS方式

1、页面刷新:

history.go(0)

location.reload()

location.href = location.href

location.assign(location)   //加载页面本身为新文档

document.execCommand('Refresh')

window.navigate(location)   //只适用于IE浏览器,建议不要使用这个方法

location.replace(location)  

2、页面跳转

//当前页跳转到通过URL方式跳转到当前页面的最后一个页面
//如果跳转到的页面需要加载的文件在缓存中的话,使用缓存中的文件,不在缓存中的话请求新文件
history.back() //当前页跳转到通过URL方式跳转到其他页面的最后一个页面
//如果跳转到的页面需要加载的文件在缓存中的话,使用缓存中的文件,不在缓存中的话请求新文件
history.forward() //设置n值的大小,实现跳转,与history.back()、history.forward()原理类似
history.go(n) location.href = url location.assign(url) //加载页面本身为新文档 window.navigate(url) //只适用于IE浏览器,建议不要使用这个方法 location.replace(url)