Window.history是一個只讀屬性,用來獲取History對象的引用,History對象提供了操作瀏覽器會話歷史(瀏覽器地址欄中訪問的頁面,以及當(dāng)前頁面中通過框架加載的頁面)的接口。

history對象.png
History對象解析
- 屬性
-
length// 當(dāng)前會話網(wǎng)站訪問記錄條數(shù) -
state// 狀態(tài) -
scrollRestoration// 允許Web應(yīng)用程序在歷史導(dǎo)航上顯式地設(shè)置默認(rèn)滾動恢復(fù)行為。此屬性可以是自動的(auto)或者手動的(manual)。
- 方法
-
back()// 回退到上一個訪問記錄 -
forward()// 前進(jìn)到下一個訪問記錄 -
go(num)// 跳轉(zhuǎn)到指定訪問記錄,num > 0 ? 回退 : 前進(jìn); -
pushState(state, title, url)、 // 添加歷史記錄到 history 對象 -
replaceState(state, title, url)// 替換歷史記錄對象
-
事件
window.onpopstate