欢迎来到吴小小的专栏!

js之history

浏览历史记录window.history,不会刷新页面内容,只会更改历史记录,用location.href 才会刷新

1. history.pushState() & history.replaceState()

pushState()和replaceState()参数一样,参数说明如下:

1、state:存储JSON字符串,可以用在popstate事件中。

2、title:现在大多数浏览器不支持或者忽略这个参数,最好用null代替

3、url:任意有效的URL,用于更新浏览器的地址栏,并不在乎URL是否已经存在地址列表中。更重要的是,它不会重新加载页面。

两个方法的主要区别就是:pushState()是在history栈中添加一个新的条目,replaceState()是替换当前的记录值

2. history.go()

历史记录的前进或者后退,参数为数值,负数:后退,整数:前进

history.go(-1) => history.back()
history.go(1) => history.forward()

posted @ 2017-11-23 18:00  吴小小  Views(258)  Comments(0Edit  收藏  举报