Webbhistorik API


Innehållsförteckning

    Visa innehållsförteckning

Web History API ger enkla metoder för att komma åt windows.history-objektet.

Objektet window.history innehåller URL:erna (webbplatserna) som användaren besökt.

Webbhistorik-API:et stöds i alla webbläsare:

Yes Yes Yes Yes Yes

History back()-metoden

Metoden back() laddar den tidigare URL:en i windows.history-listan.

Det är samma sak som att klicka på "bakåtpilen" i din webbläsare.

Exempel

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

<script>
function myFunction() {
  window.history.back();
  }
</script>



History go()-metoden

Go()-metoden laddar en specifik URL från historiklistan:

Exempel

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


Egenskaper för Historikobjekt

length

Returnerar antalet webbadresser i historiklistan

Historikobjektmetoder

back()

Laddar föregående URL i historiklistan

forward()

Laddar nästa URL i historiklistan

go()

Laddar en specifik URL från historiklistan