CKTIS / JavaScript
history.go() — traversing session history
history.go(delta) uses an offset measured in session history entries. Web IDL first converts a supplied argument to a signed 32-bit integer (long). A negative result requests backward traversal, a positive result requests forward traversal, and a zero result or an omitted argument reloads the page. Traversal is asynchronous.
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.go();
history.go(delta);history.go(delta) is a browser Web API defined by HTML, not an ECMAScript function. The offset after Web IDL converts delta to a signed 32-bit integer (long) determines the direction and number of steps. For example, 4294967295 converts to -1, so history.go(4294967295) requests traversal one entry backward. history.go(-1) corresponds to history.back(), and history.go(1) to history.forward(). An out-of-range offset does nothing; history.go(0) and history.go() reload the page.
The method returns undefined, not a Promise. Traversal is asynchronous: code after the call must not assume that the destination entry is already active. Traversal can stay within the same document or move to another document. For the illustrated traversal between entries created by pushState(), read the state in popstate.
History consists of session entries, not just separate page loads; frames can participate too. A document that is not fully active causes SecurityError; navigation restrictions can block the operation. Current browser engines support this API, but the presence of Node.js does not establish its availability.
The example creates two same-document entries, then moves back to the first. Run it on a disposable test page: it modifies history and discards any existing forward-history branch.
Examples
const button = document.createElement('button');
button.textContent = 'Run history demo';
document.body.append(button);
button.addEventListener('click', () => {
button.disabled = true;
history.pushState({ demoStep: 1 }, '');
history.pushState({ demoStep: 2 }, '');
window.addEventListener('popstate', (event) => {
console.log(`step=${event.state.demoStep}`);
}, { once: true });
history.go(-1);
}, { once: true });Result
step=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.