--- title: History slug: Web/API/History translation_of: Web/API/History ---
History
介面允許操控瀏覽器的 session history 紀錄,為當前面頁所在分頁中訪問、或於當前面頁中透過頁面框架(frame)所載入的頁面。
The History
interface doesn't inherit any property.
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
.auto
or manual
.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 {{event("popstate")}} event.The History
interface doesn't inherit any methods.
history.go(-1)
。
history.go(1)
。
go()
會重新載入目前頁面。Internet Explorer 也可以傳入字串來前往一個於瀏覽歷史列表中指定的頁面。Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "browsers.html#the-history-interface", "History")}} | {{Spec2('HTML WHATWG')}} | Adds the scrollRestoration attribute. |
{{SpecName('HTML5 W3C', "browsers.html#the-history-interface", "History")}} | {{Spec2('HTML5 W3C')}} | Initial definition. |
{{SpecName('Custom Scroll Restoration', '#web-idl', "History")}} | {{Spec2('Custom Scroll Restoration')}} | Adds the scrollRestoration attribute. |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
pushState and replaceState |
{{CompatChrome(5.0)}} | {{CompatVersionUnknown}} | 4.0 [1] | 10 | 11.5 | 5 |
scrollRestoration |
{{CompatChrome(46.0)}} | {{CompatNo}} | {{CompatGeckoDesktop("46.0")}} | {{CompatNo}} | 33 | {{CompatVersionUnknown}}[2] |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
pushState and replaceState |
2.2 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | 10 | {{CompatVersionUnknown}} | 4.3 | {{CompatVersionUnknown}} |
scrollRestoration |
{{CompatNo}} | {{CompatChrome(46.0)}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}}[2] | {{CompatChrome(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