Thuộc tính độ dài Lịch sử DOM HTML trả về các URL trong danh sách Lịch sử của cửa sổ hiện tại.
Cú pháp
Sau đây là cú pháp -
history.length
Ví dụ
Hãy để chúng tôi xem một ví dụ về thuộc tính độ dài Lịch sử DOM HTML -
<!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> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Nhấp vào nút “ xanh lam ”Để xem thời lượng lịch sử của cửa sổ trình duyệt hiện tại.