MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

History

这篇翻译不完整。请帮忙从英语翻译这篇文章

History 接口允许操作浏览器的曾经在标签页或者框架里访问的历史记录。

属性

History 接口不继承于任何属性。

History.length 只读
返回一个整数,该整数表示会话历史中元素的数目,包括当前加载的页。例如,在一个新的选项卡加载的一个页面中,这个属性返回1。
History.current 只读 已废弃 Gecko 26
返回一个代表session历史记录中活动的项目URL的DOMString,这个属性永远对web内容不可用并且已经不再被任何浏览器支持。可以使用Location.href来代替它。
History.next 只读 已废弃 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 只读 已废弃 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 
允许Web应用程序在历史导航上显式地设置默认滚动恢复行为。此属性可以是自动的(auto)或者手动的(manual)。
History.state 只读
返回一个表示历史堆栈顶部的状态的值。这是一种可以不必等待popstate 事件而查看状态而的方式。

Methods

The History interface doesn't inherit any method.

History.back()
Goes to the previous page in session history, the same action as when the user clicks the browser's Back button. Equivalent to history.go(-1).
Note: 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()
Goes to the next page in session history, the same action as when the user clicks the browser's Forward button; this is equivalent to history.go(1).
Note: 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()
Loads a page from the session history, identified by its relative location to the current page, for example -1 for the previous page or 1 for the next page. When integerDelta is out of bounds (e.g. -1 when there are no previously visited pages in the session history), the method doesn't do anything and doesn't raise an exception. Calling go() without parameters or with a non-integer argument has no effect (unlike Internet Explorer, which supports string URLs as the argument).
History.pushState()
Pushes the given data onto the session history stack with the specified title and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized.  Note that Firefox currently ignores the title parameter; for more information, see manipulating the browser history.
Note: In Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) through Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), the passed object is serialized using JSON. Starting in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.
History.replaceState()
Updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized.  Note that Firefox currently ignores the title parameter; for more information, see manipulating the browser history.
Note: In Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) through Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), the passed object is serialized using JSON. Starting in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.

Specifications

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

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
pushState and replaceState 5.0 4.0 10 11.5 5
scrollRestoration 46.0 46.0 (46.0) 未实现 33 未实现
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
pushState and replaceState 2.2 (Yes) (Yes) 10 (Yes) 4.3 (Yes)
scrollRestoration 未实现 46.0 (Yes) 未实现 (Yes) 未实现 46.0

See also

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

文档标签和贡献者

 此页面的贡献者: Cmen, xiongwilee
 最后编辑者: Cmen,