History - Web APIs 编辑

The History interface allows manipulation of the browser session history, that is the pages visited in the tab or frame that the current page is loaded in.

Properties

The History interface doesn't inherit any property.

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.
scrollRestoration
Allows web applications to explicitly set default scroll restoration behavior on history navigation. This property can be either auto or manual.
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.

Methods

The History interface doesn't inherit any methods.

back()
This asynchronous method 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). Calling this method to go back beyond the first page in the session history has no effect and doesn't raise an exception.
forward()
This asynchronous method 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). Calling this method to go forward beyond the most recent page in the session history has no effect and doesn't raise an exception.
go()
Asynchronously 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. If you specify an out-of-bounds value (for instance, specifying -1 when there are no previously-visited pages in the session history), this method silently has no effect. Calling go() without parameters or a value of 0 reloads the current page. Internet Explorer lets you specify a string, instead of an integer, to go to a specific URL in the history list.
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 all browsers but Safari currently ignore the title parameter. For more information, see Working with the History API.
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 all browsers but Safari currently ignore the title parameter. For more information, see Working with the History API.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'History' in that specification.
Living StandardAdds the scrollRestoration attribute.
HTML5
The definition of 'History' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:145 次

字数:5532

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文