bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

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

JavaScript Window History

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind JavaScript Window History?

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.

___ goBack() {
3Order

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

Window History Forward
Window History Back
JavaScript Window History

The window.history object contains the browsers history.

Window History

The window.history object can be written without the window prefix.

To protect the privacy of the users, there are limitations to how JavaScript can access this object.

Some methods

  • history.back() - same as clicking back in the browser
  • history.forward() - same as clicking forward in the browser

Window History Back

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

This is the same as clicking the Back button in the browser.

Example

Create a back button on a page:

<html>
<head>
<script>
function goBack() {
 window.history.back()
 }
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
</html>

The output of the code above will be:

Window History Forward

The history.forward() method loads the next URL in the history list.

This is the same as clicking the Forward button in the browser.

Example

Create a forward button on a page:

<html>
<head>
<script>
function goForward() {
 window.history.forward()
 }
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
</html>

The output of the code above will be:

Previous

JavaScript Window Location

Next

JavaScript Window Navigator