History.go() - Web APIs 编辑

The History.go() method loads a specific page from the session history. You can use it to move forwards and backwards through the history depending on the value of a parameter.

This method is asynchronous. Add a listener for the popstate event in order to determine when the navigation has completed.

Syntax

history.go([delta])

Parameters

delta Optional
The position in the history to which you want to move, relative to the current page. A negative value moves backwards, a positive value moves forwards. So, for example, history.go(2) moves forward two pages and history.go(-2) moves back two pages. If no value is passed or if delta equals 0, it has the same result as calling location.reload().

Examples

To move back one page (the equivalent of calling back()):

history.go(-1)

To move forward a page, just like calling forward():

history.go(1)

To move forward two pages:

history.go(2);

To move backwards by two pages:

history.go(-2);

And, finally either of the following statements will reload the current page:

history.go();
history.go(0);

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'History.go()' in that specification.
Living StandardNo change from HTML5.
HTML5
The definition of 'History.go()' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:59 次

字数:3904

最后编辑:6 年前

编辑次数:0 次

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