HTML DOM 歷史 length 屬性
HTML DOM 歷史 length 屬性返回當前視窗歷史列表中的 URL 數量。
語法
以下為語法 −
history.length
示例
我們來看一下 HTML DOM 歷史 length 屬性的一個示例 −
<!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>輸出
將產生以下輸出 −

點選“藍色”按鈕,檢視當前瀏覽器視窗的歷史記錄長度。

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP