API Cronologia web
L'API Cronologia Web fornisce metodi semplici per accedere all'oggetto windows.history.
L'oggetto window.history contiene gli URL (Siti Web) visitati dall'utente.
L'API Cronologia Web è supportata in tutti i browser:
Yes | Yes | Yes | Yes | Yes |
Il metodo History back()
Il metodo back() carica l'URL precedente nell'elenco windows.history.
È come fare clic sulla "freccia indietro" nel browser.
Esempio
<button onclick="myFunction()">Go Back</button>
<script>
function myFunction() {
window.history.back();
}
</script>
Il metodo History go()
Il metodo go() carica un URL specifico dall'elenco della cronologia:
Esempio
<button onclick="myFunction()">Go Back 2 Pages</button>
<script>
function myFunction() {
window.history.go(-2);
}
</script>
Proprietà dell'oggetto storico
Property | Description |
---|---|
length | Returns the number of URLs in the history list |
Metodi dell'oggetto della storia
Method | Description |
---|---|
back() | Loads the previous URL in the history list |
forward() | Loads the next URL in the history list |
go() | Loads a specific URL from the history list |