# Go back to the previous page

Move one step back in the session history.

Canonical: https://1loc.dev/dom/go-back-to-the-previous-page/
Version: 1.0.0
Runtime: JavaScript · modern browsers (DOM)
Verification: Usage lines executed in headless Chromium against the fixture markup; no external services
Updated: 2026-10-28

## Implementation

```javascript
function goBack() { history.back(); }
```

## Usage

```javascript
history.pushState({ step: 2 }, '', '#step-2');
const popped = new Promise(resolve => addEventListener('popstate', resolve, { once: true }));
goBack();
await popped;
location.hash; // → ''
```

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

## Limits

- history.back() is asynchronous: wait for popstate (same-document entries) or for the page to unload. It does nothing without a previous entry.
- A visible back link still needs a real href, so it works without JavaScript and for visitors who arrived directly.

The function does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/go-back-to-the-previous-page.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Executed in Chromium with a same-document history entry. Original MDX retained as inert source evidence.
