Syntax error HTML DOM History length Property

HTML DOM History length Property



The HTML DOM History length property returns of URLs in the History list of current window.

Syntax

Following is the syntax −

history.length

Example

Let us see an example of HTML DOM History length property −

 Live Demo

<!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>

Output

This will produce the following output −

Click on the “blue” button to see the history length of current browser window.

Updated on: 2019-07-30T22:30:26+05:30

136 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements