Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

history.back() — moving backward in session history

history.back() requests traversal one entry backward in browser session history. It behaves like history.go(-1); without a previous entry, it changes nothing.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

history.back()

history.back() takes no arguments and returns undefined, not a Promise. Traversal is asynchronous: the next statement does not indicate completion. The previous entry may belong to the same document or another website.

This is a browser API from the HTML Standard, not an ECMAScript feature. It is supported in current browser engines; having Node 24 in a project does not establish this API's availability. Calling it for a document that is not fully active throws SecurityError. The browser can also block the operation.

In the example, pushState() creates two entries without reloading. After traversal, popstate supplies the destination entry's state. Do not read the traversal result immediately after history.back().

Examples

const button = document.createElement('button');
button.textContent = 'Run history.back()';
document.body.append(button);

button.addEventListener('click', () => {
  button.disabled = true;
  history.pushState({ demoStep: 1 }, '');
  history.pushState({ demoStep: 2 }, '');

  window.addEventListener('popstate', (event) => {
    console.log(`demoStep: ${event.state.demoStep}`);
    button.remove();
  }, { once: true });

  history.back();
}, { once: true });

Result

demoStep: 1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources