---
title: Web History API
description: "> The Web History API provides easy methods to access the windows.history object. > > > > The window.history object contains the URLs (Web Sites) visited by the user. The Web History API is supported in all browsers: | Chrome…"
url: "https://apprentice.mn/docs/web-history-api/"
updated: "2021-05-19"
category: Javascript
---

# Web History API

> The Web History API provides easy methods to access the windows.history object.
>
>
>
> The window.history object contains the URLs (Web Sites) visited by the user.

The Web History API is supported in all browsers:

| Chrome | Internet explorer | Mozila Firefox | Safari | Opera |
| --- | --- | --- | --- | --- |
| Yes | Yes | Yes | Yes | Yes |

## The History back() Method

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

It is the same as clicking the “back arrow” in your browser.

### Example

      `<button onclick="myFunction()">Go Back</button>

<script>
function myFunction() {
  window.history.back();
}
</script>`

## The History go() Method

The go() method loads a specific URL from the history list:

### Example

      `<button onclick="myFunction()">Go Back 2 Pages</button>

<script>
function myFunction() {
  window.history.go(-2);
}
</script>`

## History Object Properties

| Property | Description |
| --- | --- |
| length | Returns the number of URLs in the history list |

## History Object Methods

| Method | Description |
| --- | --- |
| back() | Loads the previous URL in the history list |
| forward() | Loads the next URL in the history list |
| go() | Loads a specific URL from the history list |

        [https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fweb-history-api%2F&linkname=Web%20History%20API](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fweb-history-api%2F&linkname=Web%20History%20API)[https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fweb-history-api%2F&linkname=Web%20History%20API](https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fweb-history-api%2F&linkname=Web%20History%20API)[https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fweb-history-api%2F&linkname=Web%20History%20API](https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fweb-history-api%2F&linkname=Web%20History%20API)[https://www.addtoany.com/share](https://www.addtoany.com/share)
