[WebAPIs] 瀏覽記錄 Browser History API
History API @ MDN WebAPIs
在歷史紀錄中移動
keywords: back()
, forward()
, go()
/* 回到前後頁 */
window.history.back(); // 回到上一頁
window.history.forward(); // 回到下一頁
/* 移動到特定的歷史紀錄 */
window.history.go(-1); // 回到上一頁,等同於 back
window.history.go(1); // 回到下一頁,等同於 forward
window.history.go(-2); // 回到前兩頁
window.history.length; // 取得目前瀏覽記錄的總數目
加入和修改歷史紀錄
keywords: history.pushState()
, history.replaceState()
, window.onpopstate()
history.pushState()
/**
* history.pushState(stateObject, title, url);
**/
history.pushState(null, null, 'foobar');
stateObject