Web History API

Ang Web History API ay nagbibigay ng simpleng paraan para makapasok sa window.history object.

Ang window.history object ay naglalaman ng mga URL (website) na binisita ng user.

Ang lahat ng mga browser ay sumusuporta sa Web History API:

Chrome IE Firefox Safari Opera
Suportado Suportado Suportado Suportado Suportado

History back() Method

Mga back() na method ang naglulagay ng unang URL mula sa windows.history list.

This is the same as clicking the 'back arrow' in the browser.

Example

<button onclick="myFunction()">Back</button>
<script>
function myFunction() {
  window.history.back();
}
</script>

History go() Method

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

Example

<button onclick="myFunction()">Go back two pages</button>
<script>
function myFunction() {
  window.history.go(-2);
}
</script>

History Object Attribute

Attribute Description
length Return the number of URLs in the history list.

History Object Method

Method Description
back() Load the previous URL in the history list.
forward() Load the next URL in the history list.
go() Load a specific URL from the history list.