Note: History object is the effective scope of the current window.
The length property of the History object
The History object has a unique length attribute that is used to get the number of URLs in the browser's visit history. Examples are as follows:
The output of this example depends on the current page browsing record, if it is a new window to open the example, IE browser will output 0 (from 0 to calculate), and Firefox, Chrome and other browsers will output 1.
History object method
History object has the following three methods:
- history.back() : return to the previous browser page (if present)
- history.forward() : Go to next page browser (if exists)
- history.go() : Go to history list a specified page (if present)
The back() method is used to return to the previous browser page (if exists), which is equivalent to clicking the browser's return button or calling history.go (-1).
The forward() method
The forward() method is used to navigate to the next browser page (if exists), which is equivalent to clicking the browser's forward button or calling history.go (1)
go() methodThe go() method is used to go to a specific page in the history list (if exists), with the following syntax:
history.go( number|URL ) // Number : The position of the page to be accessed relative to the current page, // a negative integer indicates a backward return, // and a positive integer indicates forward. // URL : The URL to access, or a substring of the URL.
The following example has the same effect as history.back():