bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/JavaScript/Objects, Classes, and Advanced Patterns
JavaScript•Objects, Classes, and Advanced Patterns

Web History API

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Web History API?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

<___ onclick="myFunction()">Go Back</button>
3Order

Put the learning moves in the order that makes the concept easiest to apply.

History Object Properties
The History go() Method
The History back() Method

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:

YesYesYesYesYes

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>

Go Back

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>

Go Back 2 Pages

History Object Properties

PropertyDescription
lengthReturns the number of URLs in the history list

History Object Methods

MethodDescription
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

Previous

Web Geolocation API

Next

Pointer Events API