คุณสมบัติความยาวประวัติ HTML DOM ส่งคืน URL ในรายการประวัติของหน้าต่างปัจจุบัน
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
history.length
ตัวอย่าง
ให้เราดูตัวอย่างคุณสมบัติความยาวประวัติ HTML DOM -
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
}
.btn{
background-color:lightblue;
border:none;
height:2rem;
border-radius:50px;
width:60%;
margin:1rem auto;
}
.show{
font-size:2rem;
font-weight:bold;
color:orange;
}
</style>
</head>
<body>
<h1>History length Property Example</h1>
<button type="button" onclick="getHistoryLength()" class="btn">Click me to get History length
<div class="show"></div>
<script>
function getHistoryLength(){
var historyLength=history.length;
document.querySelector(".show").innerHTML = historyLength;
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คลิกที่ “สีน้ำเงิน ” เพื่อดูความยาวประวัติของหน้าต่างเบราว์เซอร์ปัจจุบัน
