If I open a new browser window and open a new page in it history.length
is 2 in both Chrome and Firefox. Does anyone know why?
Test page: http://jsbin.com/amiyaw
The History length property in HTML is used to return the count of URLs in the history list of the current browser window. The minimum value returned by this property is 1 because the current page is loaded at the moment whereas the maximum count that can be displayed in 50.
The length property returns the number of URLs in the history list of the current browser window. The property returns at least 1, because the list includes the current page. This property is useful to find out how many pages the user has visited in the current browsing session.
The "length is not a function" error occurs when we try to invoke the length property like a function instead of accessing it using dot notation. To solve the error, access the length property without parenthesis, e.g. arr. length .
That's because the new tab, or window, has a default page, which also counts as history. In Chrome's case, it's the apps/most visited page.
If you open it from a link, and thus not opening the "new tab" page inbetween, it will output 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With