Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why history.length is 2 for the first page?

Tags:

javascript

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

like image 762
Evgenii Avatar asked Mar 05 '12 09:03

Evgenii


People also ask

What is history length?

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.

What is window history length in JavaScript?

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.

Why length is not working in JavaScript?

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 .


1 Answers

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.

like image 153
Joakim Johansson Avatar answered Oct 04 '22 04:10

Joakim Johansson