HTML DOM 历史记录长度属性

htmlweb developmentfront end technology更新于 2025/6/23 2:52:17

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>

输出

这将产生以下输出 −

点击“蓝色”按钮查看当前浏览器窗口的历史记录长度。


相关文章


有用资源