Window history.back() Method

Definition and usage

history.back() The method loads the previous URL (page) in the history list.

history.back() The method is valid only when there is a previous page.

Note:

history.back() With history.go(-1) Same.

history.back() Same as clicking the 'Back' button in the browser.

See also:

history.forward() method

history.go() method

history.length method

Example

Create a back button on the page:

<button onclick="history.back()">Back</button>

The output of the above code will be:

Click back to see how it works.

(Valid only when there is a previous page in your history list)

Try it yourself

Syntax

history.back()

Parameter

None.

Return value

None.

Browser support

All browsers support history.back():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support