What is the concept of JavaScript Window History?
This article mainly explains "what is the concept of JavaScript Window History". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the concept of JavaScript Window History".
I. Preface
Window.history objects can be written without the window window prefix. To protect the privacy of users, restricted JavaScript can access this object.
History.back ()-same as clicking the back button in the browser.
History.forward ()-same as clicking the forward button in the browser.
2. History object
The window.history object contains the browser session history, a list of all pages accessed in the current frame or window, and window.history can write objects without window prefixes.
However, in order to protect the privacy of users, there are some restrictions on how JavaScript accesses this object. The window.history object contains browser history.
3. Get the number of pages visited
This history.length property returns the number of pages in the current window in the browser session history, as well as the currently loaded pages.
Example
Var result = history.length; / / returns the size of the current session history complete code: project
Number of URL in the history list:
Note: this example opens in the new framework and will be treated as a new "session":
Var result = history.length; document.getElementById ("para") [xss_clean] = result
You can use this property to find out how many pages the user visited during the current browser session.
1. Return to the previous page
The history.back () method loads the previous URL in the history list.
This is the same as clicking the back button in the browser.
Project advance
Note: clicking the forward button here will not do anything because there is no next URL in the history list:
The above code displays the following output (this example will not work if the next page does not exist in the history list):
3. Go to a specific page
You can use the history.go () method to load a specific page from the session history.
This method takes an integer as a parameter, a negative integer moves backward in the history, and a positive integer moves backward in the history.
Example
Project