History: back() method

The back() method of the History interface causes the browser to move back one page in the session history.

It has the same effect as calling history.go(-1). If there is no previous page, this method call does nothing.

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

Syntax

js
back()

Parameters

None.

Return value

None (undefined).

Exceptions

SecurityError DOMException

Thrown if the associated document is not fully active.

Examples

The following short example causes a button on the page to navigate back one entry in the session history.

HTML

html
<button id="go-back">Go back!</button>

JavaScript

js
document.getElementById("go-back").addEventListener("click", () => {
  history.back();
});

Specifications

Specification
HTML Standard
# dom-history-back-dev

Browser compatibility

BCD tables only load in the browser

See also