history对象back()、forward()、go()

时间:2023-03-08 23:59:20
history对象back()、forward()、go()

history对象back()、forward()、go()方法
history.back() 
功能:加载历史列表中的前一个URL(后退)。

语法:history.back()

调用该方法的效果等价于点击后退按钮或调用history.go(-1)。

history.forward() 
功能:加载历史列表中的下一个URL(前进)。

语法:history.forward()

调用该方法的效果等价于点击前进按钮或调用history.go(1)。

history.go() 
功能:加载历史列表中的某个具体的页面。

语法:history.go(number)

参数:
number:要访问的URL在History的URL列表中的相对位置.

-1代表前一个(forward),0代表当前,1代表(back)后一个。

1(向后) <----- 0(当前) -----> -1(向前) 
history.go(-1) == history.forward()
history.go(1)  == history.back()
history.current, history.next