翻譯不完整。請協助 翻譯此英文文件

History 介面允許操控瀏覽器的 session history 紀錄,為當前面頁所在分頁中訪問、或於當前面頁中透過頁面框架(frame)所載入的頁面。

屬性

The History interface doesn't inherit any property.

History.length Read only
Returns an Integer representing the number of elements in the session history, including the currently loaded page. For example, for a page loaded in a new tab this property returns 1.
History.current Read only 已過時 Gecko 26
Returns a DOMString representing the URL of the active item of the session history. This property was never available to web content and is no more supported by any browser. Use Location.href instead.
History.next Read only 已過時 Gecko 26
Returns a DOMString representing the URL of the next item in the session history. This property was never available to web content and is not supported by other browsers.
History.previous Read only 已過時 Gecko 26
Returns a DOMString representing the URL of the previous item in the session history. This property was never available to web content and is not supported by other browsers.
History.scrollRestoration 
Allows web applications to explicitly set default scroll restoration behavior on history navigation. This property can be either auto or manual.
History.state Read only
Returns an any value representing the state at the top of the history stack. This is a way to look at the state without having to wait for a popstate event.

方法

The History interface doesn't inherit any methods.

History.back()
回到 session history 紀錄中的前一頁,等同於使用者按下瀏覽器的上一頁按鈕。相當於 history.go(-1)
Calling this method to go back beyond the first page in the session history has no effect and doesn't raise an exception.
History.forward()
回到 session history 紀錄中的下一頁,等同於使用者按下瀏覽器的下一頁按鈕。相當於 history.go(1)
Calling this method to go forward beyond the most recent page in the session history has no effect and doesn't raise an exception.
History.go()
自 session history 紀錄中載入一個頁面,利用該頁面相對於目前頁面的所在位置,例如 -1 為前一頁或 1 為下一頁。若指定了一個超出範圍的值(舉例來說,在 session history 沒有先前訪頁面的情況下指定 -1),此方法將會是靜默(不會產生錯誤)且沒有任何效果的。不帶參數或是傳入 0 呼叫 go() 會重新載入目前頁面。Internet Explorer 也可以傳入字串來前往一個於瀏覽歷史列表中指定的頁面。
History.pushState()
插入給定的資料與指定的標題(title)以及選擇性的 URL 至 session history 堆疊(stack)中。給定的資料將被 DOM 視為不透明的(opaque);可以指定任何可被序列化的 JavaScript 物件。請注意 Firefox 目前會忽略標題(title)參數;更多資訊請參閱操控瀏覽器歷史紀錄
History.replaceState()
以指定的資料、標題(title)及可選的 URL 來更新歷史紀錄堆疊(history stack)中近期的項目。給定的資料將被 DOM 視為不透明的(opaque);可以指定任何可被序列化的 JavaScript 物件。請注意 Firefox 目前會忽略標題(title)參數;更多資訊請參閱操控瀏覽器歷史紀錄

規範

Specification Status Comment
HTML Living Standard
The definition of 'History' in that specification.
Living Standard Adds the scrollRestoration attribute.
HTML5
The definition of 'History' in that specification.
Recommendation Initial definition.
Custom Scroll Restoration - History-based API
The definition of 'History' in that specification.
Editor's Draft Adds the scrollRestoration attribute.

瀏覽器相容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
pushState and replaceState 5.0 (Yes) 4.0 [1] 10 11.5 5
scrollRestoration 46.0 No support 46.0 (46.0) No support 33 (Yes)[2]
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
pushState and replaceState 2.2 (Yes) (Yes) (Yes) 10 (Yes) 4.3 (Yes)
scrollRestoration No support 46.0 No support (Yes) No support (Yes) (Yes)[2] 46.0

[1] In Firefox 2 through 5, the passed object is serialized using JSON. Starting in Firefox 6, the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.

[2] WebKit bug 147782

參見

  • The Window.history property returning the history of the current session.

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo
 最近更新: jackblackevo,