Window.history 唯讀屬性會回傳一個 History 物件,其提供了一個介面來操控瀏覽器的 session history 紀錄(為當前面頁所在分頁中訪問、或於當前面頁中透過頁面框架(frame)所載入的頁面)。

相關範例及細節請參考操控瀏覽器歷史紀錄一文。文章中解釋了在使用 pushState()replaceState() 方法前應該要知道的安全性功能。


var historyObj = window.history;


history.back(); // 相當於按下上一頁按鈕
history.go(-1); // 相當於 history.back();


For top-level pages you can see the list of pages in the session history, accessible via the History object, in the browser's dropdowns next to the back and forward buttons.

For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history.

There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.


HTML Standard
# the-history-interface