Windows history.length property

Definition and usage

length The property returns the number of URLs in the current browser window's history list.

This property returns at least 1, because the list includes the current page.

This property is very useful for finding out how many pages the user has visited in the current browsing session.

Tip:history.back() Valid only if there is a previous page in the history list.

See also:

history.back() method

history.forward() method

history.go() method

Example

Get the number of URLs in the history list:

let length = history.length;

Try it yourself

Syntax

history.length

Parameter

None.

Return value

Type Description
Number The number of entries in the history list.

Browser Support

All Browsers Support history.length:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support