/

HTML / CSS / JavaScript Tutorial

JavaScript History method: back()

[this page | pdf | back links]

The back() method (when applied to History objects in the JavaScript BOM) loads the previous URL in the history list. It is the same as clicking the back button in the browser or applying the history.go(-1) method.

 

It has the following syntax with no parameters. It does not return a value.

 

history.back()

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse :collapse;}
</style>
</head>
<body>
Note: clicking on any of these buttons is unlikely to result in any action,
as there is no previous or subsequent URL in the URL history list<br><br>

<button onclick="historyBack()">go back a page in history list</button><br>
<button onclick="historyForward()">go back a page in history list</button><br>
<button onclick="historyGo()">go back two pages in history list</button><br>

<script>
function historyBack() {
  window.history.back();
}
function historyForward() {
  window.history.forward();
}
function historyForward() {
  window.history.go(-2);
}
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile