history.length

In this chapter you will learn:

  1. How to access the length property in history object

Length of history

history.length tells how many items are in the history stack. By testing for this value, it's possible to determine if the user's start point was your page:

<!DOCTYPE HTML> <!--  j a va2 s  .c o  m-->
<html> 
    <body> 
        <script> 
            if (history.length == 0){ 
                document.writeln("0")
            } else{
                document.writeln("more than 0")
            }


        </script> 
    </body> 
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. How to use pushstate method from history
Home » Javascript Tutorial » History
History Object
history.back()
history.forward
history.go(url/number)
history.length
history.pushState