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 |
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.
<button onclick="myFunction()">Go Back</button>
<script>
function myFunction() {
window.history.back();
}
</script>
Go()-metoden laddar en specifik URL från historiklistan:
<button onclick="myFunction()">Go Back 2 Pages</button>
<script>
function myFunction() {
window.history.go(-2);
}
</script>
Returnerar antalet webbadresser i historiklistan
Laddar föregående URL i historiklistan
Laddar nästa URL i historiklistan
Laddar en specifik URL från historiklistan