Webgeskiedenis API
Die Web History API bied maklike metodes om toegang tot die windows.history voorwerp te verkry.
Die window.history-objek bevat die URL's (webwerwe) wat deur die gebruiker besoek is.
Die Webgeskiedenis API word in alle blaaiers ondersteun:
Yes | Yes | Yes | Yes | Yes |
Die Geskiedenis terug() Metode
Die back() metode laai die vorige URL in die windows.history lys.
Dit is dieselfde as om op die "terugpyltjie" in jou blaaier te klik.
Voorbeeld
<button onclick="myFunction()">Go Back</button>
<script>
function myFunction() {
window.history.back();
}
</script>
Die History go()-metode
Die go() metode laai 'n spesifieke URL uit die geskiedenislys:
Voorbeeld
<button onclick="myFunction()">Go Back 2 Pages</button>
<script>
function myFunction() {
window.history.go(-2);
}
</script>
Geskiedenis Voorwerp Eienskappe
Property | Description |
---|---|
length | Returns the number of URLs in the history list |
Geskiedenis-objekmetodes
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 |