刷新页面的几种方式(reload,replace,meta标签,assign)

1、meta标签

<meta http-equiv="refresh" content="times">

这里content的值“times”表示的是时间,以秒为单位,是隔times秒自动刷新的。

2、window.location.reload()方法

window.location.reload(boolean)

boolean参数默认为false,表示从缓存中读取,当参数为true的时候,表示强制从服务器中读取,参考资料

3、window.location.replace()方法

window.location.replace(url)

url参数为重新加载的地址,如果是刷新页面,可以写成

window.location.replace(location.href)

这种刷新方式不会把当前页面保存在历史中,所有是无法返回当前页面的,参考资料

4、window.location.assign()方法

window.location.href(url)

这个效果是重新加载当前窗口和页面,和replace()在保存历史上是有所不同的,参考资料

注意点:

加载url错误可以看“参考资料”,我就不多说了。

猜你喜欢

转载自blog.csdn.net/qq_41422946/article/details/84283570
今日推荐