Using History to Create a Back Button

Using JavaScript‘s history object a back button can be added to the web page, passing the browser back to the previous page.

The action may either be implemented in a form, or with the use of a hyperlink.

The example given below shows the form implementation. An onclick has been added to the form button type input. The value of the onclick is set to the history object value.

<form>
  <input type="button" value="Go Back" onclick="history.go(-1)">
</form>

The hyperlink implementation uses the same history object. In this instance it is defined as the hyperlink, no onclick is included.

<a href=”javascript:history.go(-1)”>Back</a>