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