API ประวัติเว็บ
Web History API มีวิธีง่ายๆ ในการเข้าถึงอ็อบเจ็กต์ windows.history
วัตถุ window.history มี URL (เว็บไซต์) ที่ผู้ใช้เยี่ยมชม
Web History API รองรับในทุกเบราว์เซอร์:
Yes | Yes | Yes | Yes | Yes |
ประวัติย้อนหลัง () วิธีการ
วิธี back() โหลด URL ก่อนหน้าในรายการ windows.history
เหมือนกับการคลิก "ลูกศรย้อนกลับ" ในเบราว์เซอร์ของคุณ
ตัวอย่าง
<button onclick="myFunction()">Go Back</button>
<script>
function myFunction() {
window.history.back();
}
</script>
ประวัติ go() Method
go() วิธีการโหลด URL เฉพาะจากรายการประวัติ:
ตัวอย่าง
<button onclick="myFunction()">Go Back 2 Pages</button>
<script>
function myFunction() {
window.history.go(-2);
}
</script>
คุณสมบัติของออบเจ็กต์ประวัติ
Property | Description |
---|---|
length | Returns the number of URLs in the history list |
วิธีการวัตถุประวัติ
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 |